Added lilypond edition
This commit is contained in:
@@ -9,6 +9,7 @@ import magic
|
||||
from fastapi import HTTPException, UploadFile
|
||||
from folkugat_web.config import db
|
||||
from folkugat_web.dal.sql.temes import links as links_dal
|
||||
from folkugat_web.dal.sql.temes import scores as scores_dal
|
||||
from folkugat_web.log import logger
|
||||
|
||||
|
||||
@@ -46,10 +47,7 @@ async def store_file(tema_id: int, upload_file: UploadFile) -> str:
|
||||
check_mimetype(mimetype)
|
||||
|
||||
extension = mimetypes.guess_extension(mimetype) or ""
|
||||
filename = str(uuid.uuid4().hex) + extension
|
||||
filedir = db.DB_FILES_DIR / str(tema_id)
|
||||
filedir.mkdir(exist_ok=True)
|
||||
filepath = filedir / filename
|
||||
filepath = create_tema_filename(tema_id=tema_id, extension=extension)
|
||||
|
||||
with open(filepath, "wb") as f:
|
||||
_ = f.write(await upload_file.read())
|
||||
@@ -57,15 +55,34 @@ async def store_file(tema_id: int, upload_file: UploadFile) -> str:
|
||||
return get_db_file_path(filepath)
|
||||
|
||||
|
||||
def create_tema_filename(tema_id: int, extension: str = "") -> Path:
|
||||
filename = str(uuid.uuid4().hex) + extension
|
||||
filedir = db.DB_FILES_DIR / str(tema_id)
|
||||
filedir.mkdir(exist_ok=True)
|
||||
filepath = filedir / filename
|
||||
return filepath
|
||||
|
||||
|
||||
def create_tmp_filename(extension: str = "") -> Path:
|
||||
filename = str(uuid.uuid4().hex) + extension
|
||||
filedir = db.DB_FILES_DIR / "tmp"
|
||||
filedir.mkdir(exist_ok=True)
|
||||
filepath = filedir / filename
|
||||
return filepath
|
||||
|
||||
|
||||
def list_files(tema_id: str) -> list[str]:
|
||||
filedir = db.DB_FILES_DIR / str(tema_id)
|
||||
return [get_db_file_path(f) for f in filedir.iterdir()]
|
||||
|
||||
|
||||
def get_orphan_files() -> Iterator[Path]:
|
||||
alive_files = {link.url for link in links_dal.get_links()}
|
||||
link_urls = {link.url for link in links_dal.get_links()}
|
||||
score_pdf_urls = {score.pdf_url for score in scores_dal.get_scores() if score.pdf_url is not None}
|
||||
score_img_urls = {score.img_url for score in scores_dal.get_scores() if score.img_url is not None}
|
||||
alive_urls = link_urls | score_pdf_urls | score_img_urls
|
||||
return filter(
|
||||
lambda p: p.is_file() and get_db_file_path(p) not in alive_files,
|
||||
lambda p: p.is_file() and get_db_file_path(p) not in alive_urls,
|
||||
db.DB_FILES_DIR.rglob("*"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user