funapi / routes /helpers.py
imperialwool's picture
removing signature and supporting only post
367be45
raw
history blame
931 Bytes
import os
import json
import random
import string
# Deleting audio
def deleteAudio(path: str, waitInSeconds: int = 0):
config = configFile()
os.system("rm {}/{}".format(config['static-path'], path))
# Config file reading
def configFile():
with open("/app/routes/config.json", "r") as file:
config = json.loads(file.read())
return config
# Hook for yt-dlp
def thisIsHook(d):
try:
if d['total_bytes'] > 52428800:
print("\nFILE IS BIG, ABORT!!!\n")
raise Exception(f"Too long file (recieved {d['total_bytes']/1048576}MB, max is 50MB)")
except: pass
# Get variable from request
def getFromRequest(request, thing: str):
return request.json.get(thing) if request.is_json else request.form.get(thing)
def randString(len: int = 16):
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(len))