-
Notifications
You must be signed in to change notification settings - Fork 2
/
rss.js
51 lines (43 loc) · 1.08 KB
/
rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Component, createServer } from '../src/index'
import arango from 'final-arango'
import t from 'flow-runtime'
import { parse } from 'feedparser-promised'
const RssSchema = t.type('Rss',
t.object(
t.property('title', t.string()),
t.property('description', t.string(), true),
t.property('link', t.string()),
t.property('lastBuildDate', t.string(), true),
t.property('pubDate', t.string(), true)
)
)
@arango({
database: 'rss',
collection: 'Feeds'
})
export default class Rss extends Component {
path = '/rss/:rss?'
schema = RssSchema
// uniques = ['link']
async get () {
return undefined
}
async post () {
const parsedXml = await parse(this.props.body.url, {
addmeta: true
})
const { title, description, link, lastBuildDate, pubDate } = parsedXml[0].meta
const savedRss = await this.save({
title,
description,
link,
lastBuildDate,
pubDate: typeof pubDate === 'object' ? pubDate.toISOString() : pubDate
})
return { data: savedRss }
}
}
createServer({
components: [Rss],
port: 3001
})