fix: backport fixes from a sister project

This commit is contained in:
2025-06-20 23:23:00 +02:00
parent 06679ee165
commit 99e914557a
6 changed files with 43 additions and 7 deletions

View File

@@ -8,6 +8,20 @@ import ythdd_globals, ythdd_extractor
#from flask_sqlalchemy import SQLAlchemy
#import ythdd_api_v1_stats, ythdd_api_v1_user, ythdd_api_v1_info, ythdd_api_v1_query, ythdd_api_v1_meta, ythdd_api_v1_admin
def requireAuthentication(func):
@wraps(func)
def wrapper(*args, **kwargs):
token = kwargs["r"].args.get('token')
if token == lewy_globals.config['api']['api_key']:
try:
status, received, data = func(*args, **kwargs)
return status, received, data
except:
raise AssertionError(f"Function \"{func.__name__}\" does not return status, code, and data as it should!")
else:
return 401, "error", {'error_msg': "Unauthorized"}
return wrapper
def incrementBadRequests():
ythdd_globals.apiFailedRequests += 1
@@ -29,7 +43,7 @@ def stats():
"outside_api_requests": ythdd_globals.outsideApiHits,
"local_api_requests": ythdd_globals.apiRequests - ythdd_globals.outsideApiHits
}
return 200, "OK", data_to_send
return 200, "ok", data_to_send
def videoIdSanityCheck(videoId: str):
if len(videId) != 11:
@@ -129,7 +143,7 @@ def hot(data):
incrementBadRequests()
return notImplemented([data[1]]) # workaround before notImplemented is reworked
def lookup(data):
def lookup(data, request):
match data[0]:
case 'stats':
return stats()