/
index.js
65 lines (52 loc) · 1.59 KB
/
index.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
64
65
// index.js ho hoi!
'use strict';
const axios = require('axios');
const queryString = require('query-string');
const util = require('util');
const SEARCH_URL = 'https://frinkiac.com/api/search?%s';
const MEME_URL = 'https://frinkiac.com/meme/%s/%s?%s';
const CAPTION_URL = 'https://frinkiac.com/api/caption?%s';
exports.memeMap = (item, key) => {
return this.memeURL(item.Episode, item.Timestamp);
};
exports.searchURL = q => {
q = queryString.stringify({ q: q || '' });
return util.format(SEARCH_URL, q);
};
exports.memeURL = (episode, timestamp, caption) => {
episode = episode || 'S04E17';
timestamp = timestamp || '797262';
caption = caption || '';
// b64lines=Ymx1cnN0IG9mIHRpbWVzIQ==
// eventually clean emojis
if (typeof Buffer === 'function') {
caption = new Buffer(caption).toString('base64');
} else if (window && typeof window.btoa === 'function') {
caption = window.btoa(caption);
}
const query = queryString.stringify({
b64lines: caption
});
return util.format(MEME_URL, episode, timestamp, query);
};
exports.captionURL = (episode, timestamp) => {
//e=%s&t=%s
episode = episode || 'S04E17';
timestamp = timestamp || '797262';
const query = queryString.stringify({
e: episode,
t: timestamp
});
return util.format(CAPTION_URL, query);
};
exports.search = q => {
q = q || '';
const query = queryString.stringify({ q: q });
return axios(this.searchURL(q))
.catch(err => {
return err;
})
.then(res => {
return res;
});
};