feat: Implement image thumbnail generation, storage, and API endpoints for assets, including a regeneration utility.

This commit is contained in:
xds
2026-02-05 20:52:50 +03:00
parent 736e5a8c12
commit 76dd976854
26 changed files with 127 additions and 20 deletions

View File

@@ -15,8 +15,12 @@ class AssetsRepo:
return str(res.inserted_id)
async def get_assets(self, limit: int = 10, offset: int = 0) -> List[Asset]:
res = await self.collection.find({}, {"data": 0}).sort("created_at", -1).skip(offset).limit(limit).to_list(None)
async def get_assets(self, limit: int = 10, offset: int = 0, with_data: bool = False) -> List[Asset]:
args = {}
if not with_data:
args["data"] = 0
args["thumbnail"] = 0
res = await self.collection.find({}, args).sort("created_at", -1).skip(offset).limit(limit).to_list(None)
assets = []
for doc in res:
# Конвертируем ObjectId в строку и кладем в поле id
@@ -32,6 +36,7 @@ class AssetsRepo:
projection = {"_id": 1, "name": 1, "type": 1, "tg_doc_file_id": 1}
if with_data:
projection["data"] = 1
projection["thumbnail"] = 1
res = await self.collection.find_one({"_id": ObjectId(asset_id)},
projection)
@@ -63,7 +68,7 @@ class AssetsRepo:
async def get_assets_by_ids(self, asset_ids: List[str]) -> List[Asset]:
object_ids = [ObjectId(asset_id) for asset_id in asset_ids]
res = self.collection.find({"_id": {"$in": object_ids}})
res = self.collection.find({"_id": {"$in": object_ids}}, {"thumbnail": 0})
assets = []
async for doc in res:
doc["id"] = str(doc.pop("_id"))

View File

@@ -28,7 +28,9 @@ class GenerationRepo:
limit: int = 10, offset: int = 10) -> List[Generation]:
args = {}
if character_id is not None:
args["character_id"] = character_id
args["linked_character_id"] = character_id
else:
args["linked_character_id"] = None
if status is not None:
args["status"] = status
res = await self.collection.find(args).sort("created_at", -1).skip(