Media find is now sorted by created date

This commit is contained in:
Profitroll 2023-01-12 14:43:17 +01:00
parent 8cf78f4409
commit 29ef2cfe2b
2 changed files with 4 additions and 2 deletions

View File

@ -13,6 +13,7 @@ from modules.scheduler import scheduler
from modules.security import User, get_current_active_user from modules.security import User, get_current_active_user
from modules.app import app from modules.app import app
from modules.database import col_photos, col_albums, col_tokens from modules.database import col_photos, col_albums, col_tokens
from pymongo import DESCENDING
from bson.objectid import ObjectId from bson.objectid import ObjectId
from bson.errors import InvalidId 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 = {"user": current_user.user, "album": album, "filename": re.compile(q)}
db_query_count = {"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: for image in images:
output["results"].append({"id": image["_id"].__str__(), "filename": image["filename"]}) output["results"].append({"id": image["_id"].__str__(), "filename": image["filename"]})

View File

@ -12,6 +12,7 @@ from modules.app import app
from modules.database import col_videos, col_albums, col_tokens from modules.database import col_videos, col_albums, col_tokens
from bson.objectid import ObjectId from bson.objectid import ObjectId
from bson.errors import InvalidId from bson.errors import InvalidId
from pymongo import DESCENDING
from fastapi import HTTPException, UploadFile, Security from fastapi import HTTPException, UploadFile, Security
from fastapi.responses import UJSONResponse, Response 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": []} output = {"results": []}
skip = (page-1)*page_size 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: for video in videos:
output["results"].append({"id": video["_id"].__str__(), "filename": video["filename"]}) output["results"].append({"id": video["_id"].__str__(), "filename": video["filename"]})