-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.js
48 lines (39 loc) · 1.28 KB
/
backend.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
function capIt(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
let getters = {
byCategory: {
getGroups: function (baseUrl) {
let url = baseUrl + '/items/distinct?key=category';
//console.log(`getGroups: ${url}`);
return fetch(url).then(resp => resp.json())
.then(cats => {
cats = cats.filter(cat => cat).map(cat => {
return { _id: cat, title: capIt(cat), desc: ''}
});
return cats;
})
},
getItems: function(baseUrl, group) {
let url = baseUrl + '/items/key/category?q=' + group;
//console.log(`getItems: ${url}`);
return fetch(url).then(resp=>resp.json());
}
},
byAlbum: {
getGroups: function(baseUrl) {
let url = baseUrl + '/albums';
//console.log(`getGroups: ${url}`);
return fetch(url).then(resp=>resp.json());
},
getItems: function(baseUrl, group_key) {
let url = baseUrl + '/albums/items/' + group_key;
//console.log(`getItems: ${url}`);
return fetch(url).then(resp=>resp.json());
}
}
};
let hosts = [
'https://api.grin.ly',
'https://illumere.com'
];