@@ -36,8 +36,9 @@ app.get('/', (req, res) => {
3636
3737let lookup ;
3838async function checkURL ( url ) {
39+ if ( config . SAFE_BROWSING_APIKEY === "" ) return undefined ;
3940 if ( ! lookup ) lookup = require ( 'safe-browse-url-lookup' ) ( { apiKey : config . SAFE_BROWSING_APIKEY } ) ;
40- return await lookup . checkSingle ( url )
41+ return ! ( await lookup . checkSingle ( url ) )
4142}
4243
4344function generateCode ( ) {
@@ -126,8 +127,8 @@ app.get("/s/:code", async (req, res) => {
126127 if ( password ) {
127128 let hashPass = SHA256 ( password ) . toString ( ) ;
128129 if ( hashPass === db [ code ] . password ) {
129- let isSafe = ! ( await checkURL ( db [ code ] . link ) ) ;
130- if ( isSafe ) res . redirect ( db [ code ] . link ) ;
130+ let isSafe = ( await checkURL ( db [ code ] . link ) ) ;
131+ if ( isSafe || isSafe === undefined ) res . redirect ( db [ code ] . link ) ;
131132 else res . redirect ( `/warning?link=${ Base64 . encode ( db [ code ] . link ) } ` ) ;
132133 } else {
133134 res . redirect ( `/s/${ code } ` )
@@ -136,13 +137,13 @@ app.get("/s/:code", async (req, res) => {
136137 res . sendFile ( __dirname + '/public/password.html' ) ;
137138 }
138139 } else {
139- let isSafe = ! ( await checkURL ( db [ code ] . link ) ) ;
140- if ( isSafe ) res . redirect ( db [ code ] . link ) ;
140+ let isSafe = ( await checkURL ( db [ code ] . link ) ) ;
141+ if ( isSafe || isSafe === undefined ) res . redirect ( db [ code ] . link ) ;
141142 else res . redirect ( `/warning?link=${ Base64 . encode ( db [ code ] . link ) } ` ) ;
142143 }
143144 } else {
144- let isSafe = ! ( await checkURL ( db [ code ] ) ) ;
145- if ( isSafe ) res . redirect ( db [ code ] ) ;
145+ let isSafe = ( await checkURL ( db [ code ] ) ) ;
146+ if ( isSafe || isSafe === undefined ) res . redirect ( db [ code ] ) ;
146147 else res . redirect ( `/warning?link=${ Base64 . encode ( db [ code ] ) } ` ) ;
147148 }
148149 } else if ( isMongoDB ) {
@@ -164,8 +165,8 @@ app.get("/s/:code", async (req, res) => {
164165 if ( password ) {
165166 let hashPass = SHA256 ( password ) . toString ( ) ;
166167 if ( hashPass === filtered [ 0 ] . password ) {
167- let isSafe = ! ( await checkURL ( filtered [ 0 ] . link ) ) ;
168- if ( isSafe ) res . redirect ( filtered [ 0 ] . link ) ;
168+ let isSafe = ( await checkURL ( filtered [ 0 ] . link ) ) ;
169+ if ( isSafe || isSafe === undefined ) res . redirect ( filtered [ 0 ] . link ) ;
169170 else res . redirect ( `/warning?link=${ Base64 . encode ( filtered [ 0 ] . link ) } ` ) ;
170171 } else {
171172 res . redirect ( `/s/${ code } ` )
@@ -174,8 +175,8 @@ app.get("/s/:code", async (req, res) => {
174175 res . sendFile ( __dirname + '/public/password.html' ) ;
175176 }
176177 } else {
177- let isSafe = ! ( await checkURL ( filtered [ 0 ] . link ) ) ;
178- if ( isSafe ) res . redirect ( filtered [ 0 ] . link ) ;
178+ let isSafe = ( await checkURL ( filtered [ 0 ] . link ) ) ;
179+ if ( isSafe || isSafe === undefined ) res . redirect ( filtered [ 0 ] . link ) ;
179180 else res . redirect ( `/warning?link=${ Base64 . encode ( filtered [ 0 ] . link ) } ` ) ;
180181 }
181182 }
@@ -204,7 +205,7 @@ app.get("/api/s/:code", async (req, res) => {
204205 if ( password ) {
205206 let hashPass = SHA256 ( password ) . toString ( ) ;
206207 if ( hashPass === db [ code ] . password ) {
207- let isSafe = ! ( await checkURL ( db [ code ] . link ) ) ;
208+ let isSafe = ( await checkURL ( db [ code ] . link ) ) ;
208209 res . json ( { status : 200 , data : { original : db [ code ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` , safe : isSafe } } ) ;
209210 } else {
210211 res . json ( { status : 401 , data : { original : "Error: Unauthorized" , shorten : `${ config . DOMAIN } /s/${ code } ` } } )
@@ -213,11 +214,11 @@ app.get("/api/s/:code", async (req, res) => {
213214 res . json ( { status : 401 , data : { original : "Error: Unauthorized" , shorten : `${ config . DOMAIN } /s/${ code } ` } } )
214215 }
215216 } else {
216- let isSafe = ! ( await checkURL ( db [ code ] . link ) ) ;
217+ let isSafe = ( await checkURL ( db [ code ] . link ) ) ;
217218 res . json ( { status : 200 , data : { original : db [ code ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` , safe : isSafe } } ) ;
218219 }
219220 } else {
220- let isSafe = ! ( await checkURL ( db [ code ] ) ) ;
221+ let isSafe = ( await checkURL ( db [ code ] ) ) ;
221222 res . json ( { status : 200 , data : { original : db [ code ] , shorten : `${ config . DOMAIN } /s/${ code } ` , safe : isSafe } } ) ;
222223 }
223224 } else if ( isMongoDB ) {
@@ -239,15 +240,17 @@ app.get("/api/s/:code", async (req, res) => {
239240 if ( password ) {
240241 let hashPass = SHA256 ( password ) . toString ( ) ;
241242 if ( hashPass === filtered [ 0 ] . password ) {
242- res . json ( { status : 200 , data : { original : filtered [ 0 ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` } } ) ;
243+ let isSafe = ( await checkURL ( filtered [ 0 ] . link ) ) ;
244+ res . json ( { status : 200 , data : { original : filtered [ 0 ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` , safe : isSafe } } ) ;
243245 } else {
244246 res . json ( { status : 401 , data : { original : "Error: Unauthorized" , shorten : `${ config . DOMAIN } /s/${ code } ` } } )
245247 }
246248 } else {
247249 res . json ( { status : 401 , data : { original : "Error: Unauthorized" , shorten : `${ config . DOMAIN } /s/${ code } ` } } ) ;
248250 }
249251 } else {
250- res . json ( { status : 200 , data : { original : filtered [ 0 ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` } } ) ;
252+ let isSafe = ( await checkURL ( filtered [ 0 ] . link ) ) ;
253+ res . json ( { status : 200 , data : { original : filtered [ 0 ] . link , shorten : `${ config . DOMAIN } /s/${ code } ` , safe : isSafe } } ) ;
251254 }
252255 }
253256} ) ;
0 commit comments