From 29ef2cfe2bedafb75c6ca03f2feeb9dc06149c78 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 12 Jan 2023 14:43:17 +0100 Subject: [PATCH] Media find is now sorted by created date --- extensions/photos.py | 3 ++- extensions/videos.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/photos.py b/extensions/photos.py index a7bfd26..b9bcab8 100644 --- a/extensions/photos.py +++ b/extensions/photos.py @@ -13,6 +13,7 @@ from modules.scheduler import scheduler from modules.security import User, get_current_active_user from modules.app import app from modules.database import col_photos, col_albums, col_tokens +from pymongo import DESCENDING from bson.objectid import ObjectId from bson.errors import InvalidId @@ -200,7 +201,7 @@ async def photo_find(album: str, q: Union[str, None] = None, page: int = 1, page db_query = {"user": current_user.user, "album": album, "filename": re.compile(q)} db_query_count = {"user": current_user.user, "album": album, "filename": re.compile(q)} - images = list(col_photos.find(db_query, limit=page_size, skip=skip)) + images = list(col_photos.find(db_query, limit=page_size, skip=skip).sort('dates.uploaded', DESCENDING)) for image in images: output["results"].append({"id": image["_id"].__str__(), "filename": image["filename"]}) diff --git a/extensions/videos.py b/extensions/videos.py index 205e82e..e312d3c 100644 --- a/extensions/videos.py +++ b/extensions/videos.py @@ -12,6 +12,7 @@ from modules.app import app from modules.database import col_videos, col_albums, col_tokens from bson.objectid import ObjectId from bson.errors import InvalidId +from pymongo import DESCENDING from fastapi import HTTPException, UploadFile, Security from fastapi.responses import UJSONResponse, Response @@ -156,7 +157,7 @@ async def video_find(q: str, album: str, page: int = 1, page_size: int = 100, cu output = {"results": []} skip = (page-1)*page_size - videos = list(col_videos.find({"user": current_user.user, "album": album, "filename": re.compile(q)}, limit=page_size, skip=skip)) + videos = list(col_videos.find({"user": current_user.user, "album": album, "filename": re.compile(q)}, limit=page_size, skip=skip).sort('dates.uploaded', DESCENDING)) for video in videos: output["results"].append({"id": video["_id"].__str__(), "filename": video["filename"]})