feat: Implement image thumbnail generation, storage, and API endpoints for assets, including a regeneration utility.
This commit is contained in:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user