@@ -25,25 +25,25 @@ async def wrapper(request):
2525 return wrapper
2626 return decorator
2727
28- @route ("/auth" )
29- async def _ ():
30- pass
28+ def init (self ) -> None :
29+ @self .route ("/auth" )
30+ async def _ ():
31+ pass
3132
32- @route ("/download/{hash}" )
33- async def _ (self , request : web .Request , storages : List [Storage ]) -> web .Response | web .StreamResponse :
34- def check_sign (hash : str , secret : str , query : dict ) -> bool :
35- if not (s := query .get ('s' )) or not (e := query .get ('e' )): return False
36- sign = base64 .urlsafe_b64encode (hashlib .sha1 (f"{ secret } { hash } { e } " .encode ('utf-8' )).digest ()).decode ('utf-8' ).rstrip ('=' )
37- return sign == s and time .time () < int (e , 36 )
38-
39- hash = request .match_info .get ('hash' ).lower ()
40- valid = check_sign (hash , self .secret , request .query )
41- if not valid :
42- return web .Response (text = "invalid sign" , status = 403 )
43- response = web .StreamResponse (status = 200 )
44- response .headers ['x-bmclapi-hash' ] = hash
45- storage = random .randint (0 , len (storages ) - 1 )
46- data = storages [storage ].express (hash , request , response )
47- return response
33+ @self .route ("/download/{hash}" )
34+ async def _ (self , request : web .Request , storages : List [Storage ]) -> web .Response | web .StreamResponse :
35+ def check_sign (hash : str , secret : str , query : dict ) -> bool :
36+ if not (s := query .get ('s' )) or not (e := query .get ('e' )): return False
37+ sign = base64 .urlsafe_b64encode (hashlib .sha1 (f"{ secret } { hash } { e } " .encode ('utf-8' )).digest ()).decode ('utf-8' ).rstrip ('=' )
38+ return sign == s and time .time () < int (e , 36 )
39+
40+ hash = request .match_info .get ('hash' ).lower ()
41+ valid = check_sign (hash , self .secret , request .query )
42+ if not valid :
43+ return web .Response (text = "invalid sign" , status = 403 )
44+ response = web .StreamResponse (status = 200 )
45+ response .headers ['x-bmclapi-hash' ] = hash
46+ data = await random .choice (storages ).express (hash , request , response )
47+ return response
4848
4949
0 commit comments