file autodele on
This commit is contained in:
@@ -112,10 +112,17 @@ def set_metadata_and_rename(mp3_file: str, name: str, artist: str = None, album:
|
||||
DOWNLOAD_FOLDER = os.environ.get("DOWNLOAD_FOLDER","downloads") # Where the converted files will be saved
|
||||
if not os.path.exists(DOWNLOAD_FOLDER):
|
||||
os.makedirs(DOWNLOAD_FOLDER)
|
||||
|
||||
async def delay_delete_file(delay:float, file:str):
|
||||
await asyncio.sleep(delay)
|
||||
if os.path.exists(file): os.unlink(file)
|
||||
|
||||
# Throw error if the env is incorrect
|
||||
try:
|
||||
AUTODELETE_DELAY_SECS = int(os.environ.get("FILE_AUTODELETE_DELAY_SECS", 0))
|
||||
except ValueError:
|
||||
raise EnvironmentError("You must set AUTODELETE_DELAY_SECS to a valid number (int) of seconds! To disable auto delete (not recommended), set it to 0")
|
||||
|
||||
async def delay_delete_file(file:str):
|
||||
if (AUTODELETE_DELAY_SECS > 0):
|
||||
await asyncio.sleep(AUTODELETE_DELAY_SECS)
|
||||
if os.path.exists(file): os.unlink(file)
|
||||
|
||||
@app.post("/convert")
|
||||
async def create_conversion(req: Request):
|
||||
@@ -138,7 +145,7 @@ async def create_conversion(req: Request):
|
||||
file_name = final_file.split("/")[-1]
|
||||
|
||||
print("File served: " + final_file)
|
||||
asyncio.create_task(delay_delete_file(300, final_file))
|
||||
asyncio.create_task(delay_delete_file(final_file))
|
||||
|
||||
return { "file" : file_name }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user