-
Notifications
You must be signed in to change notification settings - Fork 0
/
discogs.js
54 lines (39 loc) · 1.27 KB
/
discogs.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
const _ = require('lodash');
const Discogs = require('disconnect').Client;
const DISCOGS_TOKEN = process.env.DISCOGS_TOKEN;
const PAGE_SIZE = 100;
if (!DISCOGS_TOKEN) {
throw new Error('DISCOGS_TOKEN is not defined in the ENV variables');
}
class DiscoGS {
constructor() {
const dis = new Discogs('EventbriteTest/1.2.1', {userToken: DISCOGS_TOKEN});
this._db = dis.database();
}
search({nextPage}) {
return new Promise((resolve, reject) => {
console.log(`Getting page: ${nextPage}`);
this._db.search({
type: 'artist',
per_page: PAGE_SIZE,
page: nextPage,
}).then(({pagination, results}) => {
const artists = _.map(results, ({id, title, cover_image, thumb}) => ({
id,
name: title,
imageUrl: cover_image,
thumb,
}));
console.log('Pagination:', pagination);
resolve({artists, pagination});
})
.catch((err) => {
reject(err.message);
});
});
}
getImage(url) {
return this._db.getImage(url);
}
}
module.exports = DiscoGS;