-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
63 lines (54 loc) · 1.72 KB
/
gatsby-node.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
52
53
54
55
56
57
58
59
60
61
62
63
const { UberflipSource } = require('./fetch.js');
const crypto = require('crypto');
const chalk = require('chalk');
const log = message => console.log('\n', message);
let _grant_type;
let _client_id;
let _client_secret;
exports.sourceNodes = async ({ boundActionCreators }, {
grant_type,
client_id,
client_secret,
}) => {
const { createNode } = boundActionCreators;
_grant_type = grant_type;
_client_id = client_id;
_client_secret = client_secret;
try {
const fetcher = new UberflipSource(_grant_type, _client_id, _client_secret);
const tokenInfo = await fetcher.getAccessToken(_grant_type, _client_id, _client_secret);
const streamData = await fetcher.getStreams(tokenInfo.access_token);
const promiseArray = []
streamData.data.map(stream => {
promiseArray.push(fetcher.getStreamItems(tokenInfo.access_token, stream.id))
})
log(`
${chalk.blue('info')} fetched from Uberflip API:
${chalk.bold(streamData.data.length)} streams
`);
await Promise.all(promiseArray).then(async (streams) => {
streams.map(items => {
items.data.map(item => {
console.log('item !!!!!!!!', item)
const boardDigest = crypto.createHash(`md5`).update(JSON.stringify(item.id)).digest(`hex`);
createNode({
id: 'Uberflip__Stream__'+item.id,
name: item.title,
title: item.title,
description: item.description,
url: item.url,
thumbnail_url: item.thumbnail_url,
parent_stream: item.stream.id,
internal: {
type: 'UberflipStream',
contentDigest: boardDigest
}
});
})
})
})
} catch (error) {
console.error(error);
process.exit(1);
}
};