Deploy folkugat web
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
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.log import logger
|
||||
|
||||
|
||||
async def get_mimetype(upload_file: UploadFile) -> str:
|
||||
@@ -56,3 +60,17 @@ async def store_file(tema_id: int, upload_file: UploadFile) -> str:
|
||||
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()}
|
||||
return filter(
|
||||
lambda p: p.is_file() and get_db_file_path(p) not in alive_files,
|
||||
db.DB_FILES_DIR.rglob("*"),
|
||||
)
|
||||
|
||||
|
||||
def clean_orphan_files():
|
||||
for path in get_orphan_files():
|
||||
logger.info(f"Deleting the orphan file: {path}")
|
||||
os.remove(path)
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
from typing import Optional
|
||||
|
||||
from folkugat_web.dal.sql import Connection
|
||||
from folkugat_web.dal.sql._connection import get_connection
|
||||
from folkugat_web.dal.sql.playlists import query, write
|
||||
from folkugat_web.log import logger
|
||||
from folkugat_web.model import playlists
|
||||
from folkugat_web.services.temes import links as links_service
|
||||
from folkugat_web.services.temes import query as temes_query
|
||||
|
||||
|
||||
def add_temes_to_playlist(playlist: playlists.Playlist) -> playlists.Playlist:
|
||||
for set_ in playlist.sets:
|
||||
add_temes_to_set(set_)
|
||||
_ = add_temes_to_set(set_)
|
||||
return playlist
|
||||
|
||||
|
||||
def add_temes_to_set(set_: playlists.Set) -> playlists.Set:
|
||||
for tema_in_set in set_.temes:
|
||||
add_tema_to_tema_in_set(tema_in_set)
|
||||
_ = add_tema_to_tema_in_set(tema_in_set)
|
||||
return set_
|
||||
|
||||
|
||||
def add_tema_to_tema_in_set(tema_in_set: playlists.TemaInSet) -> playlists.TemaInSet:
|
||||
if tema_in_set.tema_id is not None:
|
||||
tema_in_set.tema = temes_query.get_tema_by_id(tema_in_set.tema_id)
|
||||
if not tema_in_set.tema:
|
||||
logger.error("fCould not load tune in set: {tema_in_set}")
|
||||
else:
|
||||
_ = links_service.add_links_to_tema(tema_in_set.tema)
|
||||
return tema_in_set
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ def _apply_limit_offset(limit: int, offset: int) -> Callable[[Iterable[model.Tem
|
||||
|
||||
def busca_temes(query: str, hidden: bool = False, limit: int = 10, offset: int = 0) -> list[model.Tema]:
|
||||
t0 = time.time()
|
||||
|
||||
with get_connection() as con:
|
||||
result = (
|
||||
FnChain.transform(temes_q.get_tema_id_to_ngrams(con).items()) |
|
||||
|
||||
Reference in New Issue
Block a user