forked from shouko/radichu-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.js
37 lines (33 loc) · 821 Bytes
/
search.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
const fetch = require('node-fetch');
const { uid, searchEndpoint } = require('./config');
const baseParams = [
// [ 'key', '' ],
// [ 'area_id', 'JP13' ],
['filter', 'past'],
['start_day', ''],
['end_day', ''],
['region_id', ''],
['page_idx', '0'],
['uid', uid],
['row_limit', '50'],
['app_id', 'pc'],
['action_id', '0'],
];
const buildQueryUrl = (key, areaId) => {
const query = [
...baseParams,
['key', encodeURIComponent(key)],
['area_id', `JP${areaId}`],
].map((e) => e.join('=')).join('&');
return `${searchEndpoint}?${query}`;
};
const search = async (key, areaId) => fetch(buildQueryUrl(key, areaId))
.then((r) => r.json())
.then((r) => {
if (!r || !Array.isArray(r.data)) return [];
return r.data;
})
.catch(() => []);
module.exports = {
search,
};