File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments