fix: stats and plalist images

This commit is contained in:
cwilvx
2025-02-25 23:57:53 +03:00
parent 620974561c
commit bcd4f6688c
3 changed files with 22 additions and 7 deletions
+16 -4
View File
@@ -8,9 +8,11 @@ import pathlib
from typing import Any
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 APIBlueprint
from flask_openapi3 import APIBlueprint, FileStorage as _FileStorage
from app import models
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):
image: Any = Field(..., description="The image file")
image: FileStorage = Field(description="The image file")
name: str = Field(..., description="The name of the playlist")
settings: str = Field(
...,
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
View File
@@ -307,7 +307,7 @@ class FavoritesTable(Base):
res = next(result).scalar()
if res:
return res[0]
return res
return 0
@@ -410,7 +410,7 @@ class PlaylistTable(Base):
playlist["userid"] = get_current_userid()
result = cls.insert_one(playlist)
return next(result).lastrowid
return result.lastrowid
@classmethod
def check_exists_by_name(cls, name: str):
+4 -1
View File
@@ -75,7 +75,10 @@ def get_tracks_in_period(start_time: int, end_time: int, userid: int | None = No
tracks: dict[str, Track] = {}
duration = 0
total = 0
for scrobble in scrobbles:
total += 1
if scrobble.trackhash not in tracks:
try:
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
duration += scrobble.duration
return list(tracks.values()), len(scrobbles), duration
return list(tracks.values()), total, duration
T = TypeVar("T")