Skip to content

Commit 1fb71d5

Browse files
committed
New server: embedgram
1 parent 2badda9 commit 1fb71d5

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

servers/embedgram.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* embedgram resolver
2+
* @lscofield
3+
* GNU
4+
*/
5+
const skkchecker = require('../lib/skkchecker');
6+
const cheerio = require('cheerio');
7+
8+
exports.index = function (req, res) {
9+
//Optional check, only if you need to restrict access
10+
// to unautorized apps, skk is signature and auth is
11+
// unautorized signal
12+
// see the config file to more info
13+
const auth = 'auth' in req.body ? req.body.auth : req.query.auth;
14+
const authJSON = Buffer.from(auth, 'base64').toString('utf8');
15+
const granted = skkchecker.check(authJSON);
16+
if (granted != '') {
17+
// no autorized app block
18+
// return a random troll video
19+
// if the app is unautorized
20+
res.json({ status: 'ok', url: granted });
21+
} else {
22+
// autorized app block
23+
const source = 'source' in req.body ? req.body.source : req.query.source;
24+
const mode = 'mode' in req.body ? req.body.mode : req.query.mode;
25+
var html = Buffer.from(source, 'base64').toString('utf8');
26+
var mp4 = null;
27+
28+
const $ = cheerio.load(html);
29+
30+
try {
31+
mp4 = $('#my-video').children().first().attr('src');
32+
} catch (e) {
33+
mp4 = null;
34+
}
35+
36+
mp4 = mp4 == null ? '' : mp4;
37+
38+
res.json({ status: mp4 == '' ? 'error' : 'ok', url: mp4 });
39+
40+
}
41+
};

0 commit comments

Comments
 (0)