mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
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:
+6
-5
@@ -14,7 +14,7 @@ from flask_openapi3 import Tag
|
||||
from flask_openapi3 import APIBlueprint
|
||||
|
||||
from app.db.sqlite.auth import SQLiteAuthMethods as authdb
|
||||
from app.utils.auth import check_password, encode_password
|
||||
from app.utils.auth import check_password, hash_password
|
||||
from app.config import UserConfig
|
||||
|
||||
bp_tag = Tag(name="Auth", description="Authentication stuff")
|
||||
@@ -113,7 +113,7 @@ def update_profile(body: UpdateProfileBody):
|
||||
user["roles"] = json.dumps(body.roles)
|
||||
|
||||
if user["password"]:
|
||||
user["password"] = encode_password(user["password"])
|
||||
user["password"] = hash_password(user["password"])
|
||||
|
||||
# remove empty values
|
||||
clean_user = {k: v for k, v in user.items() if v}
|
||||
@@ -132,7 +132,7 @@ def create_user(body: UpdateProfileBody):
|
||||
|
||||
user = {
|
||||
"username": body.username,
|
||||
"password": encode_password(body.password),
|
||||
"password": hash_password(body.password),
|
||||
"roles": json.dumps([]),
|
||||
}
|
||||
|
||||
@@ -232,7 +232,9 @@ def get_all_users(query: GetAllUsersQuery):
|
||||
users = authdb.get_all_users()
|
||||
|
||||
is_admin = current_user and "admin" in current_user["roles"]
|
||||
settings['enableGuest'] = [user for user in users if user.username == "guest"].__len__() > 0
|
||||
settings["enableGuest"] = [
|
||||
user for user in users if user.username == "guest"
|
||||
].__len__() > 0
|
||||
|
||||
# if user is admin, also return settings
|
||||
if is_admin:
|
||||
@@ -252,7 +254,6 @@ def get_all_users(query: GetAllUsersQuery):
|
||||
):
|
||||
return res
|
||||
|
||||
|
||||
# remove guest user
|
||||
# if not settings["enableGuest"]:
|
||||
# users = [user for user in users if user.username != "guest"]
|
||||
|
||||
+59
-39
@@ -13,6 +13,9 @@ api = APIBlueprint("imgserver", __name__, url_prefix="/img", abp_tags=[bp_tag])
|
||||
|
||||
|
||||
def send_fallback_img(filename: str = "default.webp"):
|
||||
"""
|
||||
Returns the fallback image from the assets folder.
|
||||
"""
|
||||
folder = Paths.get_assets_path()
|
||||
img = Path(folder) / filename
|
||||
|
||||
@@ -22,6 +25,18 @@ def send_fallback_img(filename: str = "default.webp"):
|
||||
return send_from_directory(folder, filename)
|
||||
|
||||
|
||||
def send_file_or_fallback(folder: str, filename: str, fallback: str = "default.webp"):
|
||||
"""
|
||||
Returns the file from the folder or the fallback image.
|
||||
"""
|
||||
fpath = Path(folder) / filename
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, filename)
|
||||
|
||||
return send_fallback_img(fallback)
|
||||
|
||||
|
||||
class ImagePath(BaseModel):
|
||||
imgpath: str = Field(
|
||||
description="The image filename",
|
||||
@@ -43,62 +58,72 @@ class ImagePath(BaseModel):
|
||||
# return send_fallback_img()
|
||||
|
||||
|
||||
@api.get("/t/<imgpath>")
|
||||
# TRACK THUMBNAILS
|
||||
@api.get("/thumbnail/<imgpath>")
|
||||
def send_lg_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get large thumbnail (500 x 500)
|
||||
"""
|
||||
folder = Paths.get_lg_thumb_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img()
|
||||
return send_file_or_fallback(folder, path.imgpath)
|
||||
|
||||
|
||||
@api.get("/t/s/<imgpath>")
|
||||
@api.get("/thumbnail/xsmall/<imgpath>")
|
||||
def send_xsm_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get extra small thumbnail (64px)
|
||||
"""
|
||||
folder = Paths.get_xsm_thumb_path()
|
||||
return send_file_or_fallback(folder, path.imgpath)
|
||||
|
||||
|
||||
@api.get("/thumbnail/small/<imgpath>")
|
||||
def send_sm_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get small thumbnail (64 x 64)
|
||||
Get small thumbnail (96px)
|
||||
"""
|
||||
folder = Paths.get_sm_thumb_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img()
|
||||
return send_file_or_fallback(folder, path.imgpath)
|
||||
|
||||
|
||||
@api.get("/a/<imgpath>")
|
||||
@api.get("/thumbnail/medium/<imgpath>")
|
||||
def send_md_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get medium thumbnail (256px)
|
||||
"""
|
||||
folder = Paths.get_md_thumb_path()
|
||||
return send_file_or_fallback(folder, path.imgpath)
|
||||
|
||||
|
||||
# ARTISTS
|
||||
@api.get("/artist/<imgpath>")
|
||||
def send_lg_artist_image(path: ImagePath):
|
||||
"""
|
||||
Get large artist image (500 x 500)
|
||||
"""
|
||||
folder = Paths.get_artist_img_lg_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("artist.webp")
|
||||
folder = Paths.get_lg_artist_img_path()
|
||||
return send_file_or_fallback(folder, path.imgpath, "artist.webp")
|
||||
|
||||
|
||||
@api.get("/a/s/<imgpath>")
|
||||
@api.get("/artist/small/<imgpath>")
|
||||
def send_sm_artist_image(path: ImagePath):
|
||||
"""
|
||||
Get small artist image (64 x 64)
|
||||
Get small artist image (128)
|
||||
"""
|
||||
folder = Paths.get_artist_img_sm_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("artist.webp")
|
||||
folder = Paths.get_sm_artist_img_path()
|
||||
return send_file_or_fallback(folder, path.imgpath, "artist.webp")
|
||||
|
||||
|
||||
@api.get("/artist/medium/<imgpath>")
|
||||
def send_md_artist_image(path: ImagePath):
|
||||
"""
|
||||
Get medium artist image (256px)
|
||||
"""
|
||||
folder = Paths.get_md_artist_img_path()
|
||||
return send_file_or_fallback(folder, path.imgpath, "artist.webp")
|
||||
|
||||
|
||||
# PLAYLISTS
|
||||
class PlaylistImagePath(BaseModel):
|
||||
imgpath: str = Field(
|
||||
description="The image path",
|
||||
@@ -106,7 +131,7 @@ class PlaylistImagePath(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
@api.get("/p/<imgpath>")
|
||||
@api.get("/playlist/<imgpath>")
|
||||
def send_playlist_image(path: PlaylistImagePath):
|
||||
"""
|
||||
Get playlist image
|
||||
@@ -114,9 +139,4 @@ def send_playlist_image(path: PlaylistImagePath):
|
||||
Images are constructed as '{playlist_id}.webp'
|
||||
"""
|
||||
folder = Paths.get_playlist_img_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("playlist.svg")
|
||||
return send_file_or_fallback(folder, path.imgpath, "playlist.svg")
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ api = APIBlueprint("playlists", __name__, url_prefix="/playlists", abp_tags=[tag
|
||||
|
||||
PL = SQLitePlaylistMethods
|
||||
|
||||
|
||||
class SendAllPlaylistsQuery(BaseModel):
|
||||
no_images: bool = Field(False, description="Whether to include images")
|
||||
|
||||
@@ -410,7 +411,7 @@ def save_item_as_playlist(body: SavePlaylistAsItemBody):
|
||||
filename = itemhash + ".webp"
|
||||
|
||||
base_path = (
|
||||
Paths.get_artist_img_lg_path()
|
||||
Paths.get_lg_artist_img_path()
|
||||
if itemtype == "artist"
|
||||
else Paths.get_lg_thumb_path()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user