Files
oki.cx-file-share/models.py
dagger 9f0832a608
Some checks failed
Test and Build Docker Image / Test-Build (push) Failing after 50s
Test and Build Docker Image / Build-Image (push) Has been cancelled
shorten file name
2026-06-16 10:45:59 -04:00

19 lines
594 B
Python

import random
import string
import os
import shutil
def UploadFile(file, filename, content_type):
def randmname(size=6, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
split_filename = filename.split('.')
rand_filename = f"{randmname(5)}.{split_filename[1]}"
with open(f'files/{rand_filename}','wb',100*(2**20)) as buffer:
shutil.copyfileobj(file.file, buffer)
cdn_info = {
"url" : f"https://cdn.oki.cx/files/{rand_filename}",
"content_type" : content_type
}
return cdn_info