@miso.ai/server-feed 0.6.3-beta.6 → 0.6.3-beta.8
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 +6 -11
- package/package.json +2 -2
- package/src/stream/feed.js +8 -6
- package/src/stream/index.js +1 -2
- package/src/version.js +1 -1
- package/src/stream/raw.js +0 -28
package/cli/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { yargs, stream } from '@miso.ai/server-commons';
|
|
3
|
-
import { version,
|
|
3
|
+
import { version, feedStreams } from '../src/index.js';
|
|
4
4
|
|
|
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
|
+
...feedStreams(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.8",
|
|
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.8"
|
|
24
24
|
}
|
package/src/stream/feed.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
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 feedStreams({ parse, after, update, transform } = {}) {
|
|
8
7
|
const threshold = update ? (Date.now() - parseDuration(update)) : startOfDate(after);
|
|
8
|
+
const streams = [
|
|
9
|
+
new FeedParser(parse),
|
|
10
|
+
];
|
|
9
11
|
if (threshold) {
|
|
10
|
-
|
|
12
|
+
streams.push(new DateFilterStream(threshold));
|
|
11
13
|
}
|
|
12
14
|
if (transform) {
|
|
13
|
-
|
|
15
|
+
streams.push(new ArticleTransformStream());
|
|
14
16
|
}
|
|
15
|
-
return
|
|
17
|
+
return streams;
|
|
16
18
|
}
|
package/src/stream/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as rawFeedStream } from './raw.js';
|
|
1
|
+
export { default as feedStreams } from './feed.js';
|
|
3
2
|
export { default as ArticleTransformStream } from './transform.js';
|
|
4
3
|
export { default as DateFilterStream } from './date-filter.js';
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.3-beta.
|
|
1
|
+
export default '0.6.3-beta.8';
|
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
|
-
}
|