@miso.ai/server-feed 0.6.3-beta.6 → 0.6.3-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +5 -10
- package/package.json +2 -2
- package/src/stream/feed.js +3 -3
- package/src/stream/index.js +0 -1
- package/src/version.js +1 -1
- package/src/stream/raw.js +0 -28
package/cli/index.js
CHANGED
|
@@ -5,12 +5,6 @@ import { version, feedStream } from '../src/index.js';
|
|
|
5
5
|
yargs.build(yargs => {
|
|
6
6
|
yargs
|
|
7
7
|
.env('MISO_FEED')
|
|
8
|
-
.option('url', {
|
|
9
|
-
type: 'string',
|
|
10
|
-
})
|
|
11
|
-
.option('auth', {
|
|
12
|
-
type: 'string',
|
|
13
|
-
})
|
|
14
8
|
.option('after', {
|
|
15
9
|
alias: 'a',
|
|
16
10
|
describe: 'Only include records after this time',
|
|
@@ -30,16 +24,17 @@ yargs.build(yargs => {
|
|
|
30
24
|
})
|
|
31
25
|
.hide('debug')
|
|
32
26
|
.command({
|
|
33
|
-
command: '*
|
|
34
|
-
description: '
|
|
27
|
+
command: '*',
|
|
28
|
+
description: 'Parse items from feed content',
|
|
35
29
|
handler: run,
|
|
36
30
|
})
|
|
37
31
|
.version(version);
|
|
38
32
|
});
|
|
39
33
|
|
|
40
|
-
async function run(
|
|
34
|
+
async function run(options) {
|
|
41
35
|
await stream.pipeline(
|
|
42
|
-
|
|
36
|
+
process.stdin,
|
|
37
|
+
feedStream(options),
|
|
43
38
|
new stream.OutputStream(),
|
|
44
39
|
);
|
|
45
40
|
}
|
package/package.json
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"simonpai <simon.pai@askmiso.com>"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@miso.ai/server-commons": "0.6.3-beta.
|
|
19
|
+
"@miso.ai/server-commons": "0.6.3-beta.7",
|
|
20
20
|
"feedparser": "^2.2.10",
|
|
21
21
|
"node-fetch": "^3.3.2"
|
|
22
22
|
},
|
|
23
|
-
"version": "0.6.3-beta.
|
|
23
|
+
"version": "0.6.3-beta.7"
|
|
24
24
|
}
|
package/src/stream/feed.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { parseDuration, startOfDate } from '@miso.ai/server-commons';
|
|
2
|
-
import
|
|
2
|
+
import FeedParser from 'feedparser';
|
|
3
3
|
import DateFilterStream from './date-filter.js';
|
|
4
4
|
import ArticleTransformStream from './transform.js';
|
|
5
5
|
|
|
6
|
-
export default
|
|
7
|
-
let stream = await rawFeedStream(url, { fetch, parse });
|
|
6
|
+
export default function feedStream({ parse, after, update, transform } = {}) {
|
|
8
7
|
const threshold = update ? (Date.now() - parseDuration(update)) : startOfDate(after);
|
|
8
|
+
let stream = new FeedParser(parse);
|
|
9
9
|
if (threshold) {
|
|
10
10
|
stream = stream.pipe(new DateFilterStream(threshold));
|
|
11
11
|
}
|
package/src/stream/index.js
CHANGED
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.3-beta.
|
|
1
|
+
export default '0.6.3-beta.7';
|
package/src/stream/raw.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import fetch, { Headers } from 'node-fetch';
|
|
3
|
-
import FeedParser from 'feedparser';
|
|
4
|
-
|
|
5
|
-
export default async function rawFeedStream(url, { fetch: fetchOptions, parse: parseOptions } = {}) {
|
|
6
|
-
const { status, body } = await fetch(url, buildFetchOptions(fetchOptions));
|
|
7
|
-
if (status !== 200) {
|
|
8
|
-
throw new Error(`Failed to fetch ${url}: ${status}`);
|
|
9
|
-
}
|
|
10
|
-
return body.pipe(new FeedParser(parseOptions));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function buildFetchOptions({ headers, auth, ...options } = {}) {
|
|
14
|
-
headers = new Headers(headers);
|
|
15
|
-
if (auth) {
|
|
16
|
-
if (typeof auth === 'object' && auth.username && auth.password) {
|
|
17
|
-
auth = `${auth.username}:${auth.password}`;
|
|
18
|
-
}
|
|
19
|
-
if (typeof auth !== 'string') {
|
|
20
|
-
throw new TypeError(`Invalid auth: must me a string or an object.`);
|
|
21
|
-
}
|
|
22
|
-
headers.set('Authorization', 'Basic ' + Buffer.from(auth).toString('base64'));
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
...options,
|
|
26
|
-
headers,
|
|
27
|
-
};
|
|
28
|
-
}
|