implement CLI password recovery (hacky :omg:)

+ rewrite migrations logic
+ rename encode_password to hash_password
+ update image sizes (add medium size)
+ rename image endpoints
This commit is contained in:
cwilvx
2024-05-11 21:26:03 +03:00
parent 1e857c1e89
commit b40f05cc7c
21 changed files with 306 additions and 152 deletions
+27 -11
View File
@@ -55,13 +55,22 @@ def get_artist_image_link(artist: str):
# TODO: Move network calls to utils/network.py
class DownloadImage:
def __init__(self, url: str, name: str) -> None:
sm_path = Path(settings.Paths.get_artist_img_sm_path()) / name
lg_path = Path(settings.Paths.get_artist_img_lg_path()) / name
img = self.download(url)
if img is not None:
self.save_img(img, sm_path, lg_path)
if img is None:
return
sm_path = Path(settings.Paths.get_sm_artist_img_path()) / name
lg_path = Path(settings.Paths.get_lg_artist_img_path()) / name
md_path = Path(settings.Paths.get_md_artist_img_path()) / name
entries = [
(lg_path, None), # save in the original size
(sm_path, settings.Defaults.SM_ARTIST_IMG_SIZE),
(md_path, settings.Defaults.MD_ARTIST_IMG_SIZE),
]
self.save_img(img, entries)
@staticmethod
def download(url: str) -> Image.Image | None:
@@ -74,14 +83,21 @@ class DownloadImage:
return None
@staticmethod
def save_img(img: Image.Image, sm_path: Path, lg_path: Path):
def save_img(img: Image.Image, entries: list[tuple[Path, int | None]]):
"""
Saves the image to the destinations.
"""
img.save(lg_path, format="webp")
ratio = img.width / img.height
for entry in entries:
path, size = entry
sm_size = settings.Defaults.SM_ARTIST_IMG_SIZE
img.resize((sm_size, sm_size), Image.ANTIALIAS).save(sm_path, format="webp")
if size is None:
img.save(path, format="webp")
continue
img.resize((size, int(size / ratio)), Image.ANTIALIAS).save(
path, format="webp"
)
class CheckArtistImages:
@@ -90,7 +106,7 @@ class CheckArtistImages:
CHECK_ARTIST_IMAGES_KEY = instance_key
# read all files in the artist image folder
path = settings.Paths.get_artist_img_sm_path()
path = settings.Paths.get_sm_artist_img_path()
processed = "".join(os.listdir(path)).replace("webp", "")
# filter out artists that already have an image
@@ -126,7 +142,7 @@ class CheckArtistImages:
return
img_path = (
Path(settings.Paths.get_artist_img_sm_path()) / f"{artist.artisthash}.webp"
Path(settings.Paths.get_sm_artist_img_path()) / f"{artist.artisthash}.webp"
)
if img_path.exists():
+1 -1
View File
@@ -42,7 +42,7 @@ def process_color(item_hash: str, is_album=True):
path = (
settings.Paths.get_sm_thumb_path()
if is_album
else settings.Paths.get_artist_img_sm_path()
else settings.Paths.get_sm_artist_img_path()
)
path = Path(path) / (item_hash + ".webp")
+10 -8
View File
@@ -33,20 +33,22 @@ def extract_thumb(filepath: str, webp_path: str, overwrite=False) -> bool:
"""
lg_img_path = os.path.join(Paths.get_lg_thumb_path(), webp_path)
sm_img_path = os.path.join(Paths.get_sm_thumb_path(), webp_path)
xms_img_path = os.path.join(Paths.get_xsm_thumb_path(), webp_path)
md_img_path = os.path.join(Paths.get_md_thumb_path(), webp_path)
tsize = Defaults.THUMB_SIZE
sm_tsize = Defaults.SM_THUMB_SIZE
images = [
(lg_img_path, Defaults.LG_THUMB_SIZE),
(sm_img_path, Defaults.SM_THUMB_SIZE),
(xms_img_path, Defaults.XSM_THUMB_SIZE),
(md_img_path, Defaults.MD_THUMB_SIZE),
]
def save_image(img: Image.Image):
width, height = img.size
ratio = width / height
img.resize((tsize, int(tsize / ratio)), Image.ANTIALIAS).save(
lg_img_path, "webp"
)
img.resize((sm_tsize, int(sm_tsize / ratio)), Image.ANTIALIAS).save(
sm_img_path, "webp"
)
for path, size in images:
img.resize((size, int(size / ratio)), Image.ANTIALIAS).save(path, "webp")
if not overwrite and os.path.exists(sm_img_path):
img_size = os.path.getsize(sm_img_path)