mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix: stats and plalist images
This commit is contained in:
+16
-4
@@ -8,9 +8,11 @@ import pathlib
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from PIL import UnidentifiedImageError, Image
|
from PIL import UnidentifiedImageError, Image
|
||||||
from pydantic import BaseModel, Field
|
from pydantic_core import core_schema
|
||||||
|
from pydantic import BaseModel, Field, GetCoreSchemaHandler
|
||||||
|
|
||||||
from flask_openapi3 import Tag
|
from flask_openapi3 import Tag
|
||||||
from flask_openapi3 import APIBlueprint
|
from flask_openapi3 import APIBlueprint, FileStorage as _FileStorage
|
||||||
|
|
||||||
from app import models
|
from app import models
|
||||||
from app.api.apischemas import GenericLimitSchema
|
from app.api.apischemas import GenericLimitSchema
|
||||||
@@ -251,13 +253,23 @@ def get_playlist(path: PlaylistIDPath, query: GetPlaylistQuery):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class FileStorage(_FileStorage):
|
||||||
|
@classmethod
|
||||||
|
def __get_pydantic_core_schema__(
|
||||||
|
cls, _source: Any, handler: GetCoreSchemaHandler
|
||||||
|
) -> core_schema.CoreSchema:
|
||||||
|
return core_schema.with_info_plain_validator_function(cls.validate)
|
||||||
|
|
||||||
|
|
||||||
class UpdatePlaylistForm(BaseModel):
|
class UpdatePlaylistForm(BaseModel):
|
||||||
image: Any = Field(..., description="The image file")
|
image: FileStorage = Field(description="The image file")
|
||||||
name: str = Field(..., description="The name of the playlist")
|
name: str = Field(..., description="The name of the playlist")
|
||||||
settings: str = Field(
|
settings: str = Field(
|
||||||
...,
|
...,
|
||||||
description="The settings of the playlist",
|
description="The settings of the playlist",
|
||||||
example='{"has_gif": false, "banner_pos": 50, "square_img": false, "pinned": false}',
|
json_schema_extra={
|
||||||
|
"example": '{"has_gif": false, "banner_pos": 50, "square_img": false, "pinned": false}'
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -307,7 +307,7 @@ class FavoritesTable(Base):
|
|||||||
res = next(result).scalar()
|
res = next(result).scalar()
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
return res[0]
|
return res
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ class PlaylistTable(Base):
|
|||||||
playlist["userid"] = get_current_userid()
|
playlist["userid"] = get_current_userid()
|
||||||
result = cls.insert_one(playlist)
|
result = cls.insert_one(playlist)
|
||||||
|
|
||||||
return next(result).lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_exists_by_name(cls, name: str):
|
def check_exists_by_name(cls, name: str):
|
||||||
|
|||||||
+4
-1
@@ -75,7 +75,10 @@ def get_tracks_in_period(start_time: int, end_time: int, userid: int | None = No
|
|||||||
tracks: dict[str, Track] = {}
|
tracks: dict[str, Track] = {}
|
||||||
duration = 0
|
duration = 0
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
for scrobble in scrobbles:
|
for scrobble in scrobbles:
|
||||||
|
total += 1
|
||||||
if scrobble.trackhash not in tracks:
|
if scrobble.trackhash not in tracks:
|
||||||
try:
|
try:
|
||||||
track = copy.deepcopy(
|
track = copy.deepcopy(
|
||||||
@@ -92,7 +95,7 @@ def get_tracks_in_period(start_time: int, end_time: int, userid: int | None = No
|
|||||||
tracks[scrobble.trackhash].playduration += scrobble.duration
|
tracks[scrobble.trackhash].playduration += scrobble.duration
|
||||||
duration += scrobble.duration
|
duration += scrobble.duration
|
||||||
|
|
||||||
return list(tracks.values()), len(scrobbles), duration
|
return list(tracks.values()), total, duration
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|||||||
Reference in New Issue
Block a user