From c693756a435d216f61cc93eec127e0cc8713e87f Mon Sep 17 00:00:00 2001 From: profitroll Date: Tue, 10 Jan 2023 15:23:49 +0100 Subject: [PATCH] Added upload and modify dates --- extensions/photos.py | 20 ++++++++++++++++++-- extensions/videos.py | 23 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/extensions/photos.py b/extensions/photos.py index e8f4132..a7bfd26 100644 --- a/extensions/photos.py +++ b/extensions/photos.py @@ -76,7 +76,23 @@ async def photo_upload(file: UploadFile, album: str, ignore_duplicates: bool = F ) coords = extract_location(path.join("data", "users", current_user.user, "albums", album, filename)) - uploaded = col_photos.insert_one( {"user": current_user.user, "album": album, "hash": file_hash, "filename": filename, "location": [coords["lng"], coords["lat"], coords["alt"]]} ) + uploaded = col_photos.insert_one( + { + "user": current_user.user, + "album": album, + "hash": file_hash, + "filename": filename, + "dates": { + "uploaded": datetime.utcnow(), + "modifies": datetime.utcnow() + }, + "location": [ + coords["lng"], + coords["lat"], + coords["alt"] + ] + } + ) if compress is True: scheduler.add_job(compress_image, trigger="date", run_date=datetime.now()+timedelta(seconds=1), args=[path.join("data", "users", current_user.user, "albums", album, filename)]) @@ -128,7 +144,7 @@ async def photo_move(id: str, album: str, current_user: User = Security(get_curr else: filename = image["filename"] - col_photos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename}} ) + col_photos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename, "dates.modified": datetime.utcnow()}} ) move( path.join("data", "users", current_user.user, "albums", image["album"], image["filename"]), diff --git a/extensions/videos.py b/extensions/videos.py index f409627..205e82e 100644 --- a/extensions/videos.py +++ b/extensions/videos.py @@ -6,6 +6,7 @@ from magic import Magic from datetime import datetime from os import makedirs, path, remove from classes.models import Video, SearchResults +#from modules.unified_exif_reader import extract_location from modules.security import User, get_current_active_user from modules.app import app from modules.database import col_videos, col_albums, col_tokens @@ -49,8 +50,24 @@ async def video_upload(file: UploadFile, album: str, current_user: User = Securi # }, # status_code=HTTP_409_CONFLICT # ) - - uploaded = col_videos.insert_one( {"user": current_user.user, "album": album, "filename": filename} ) + + #coords = extract_location(path.join("data", "users", current_user.user, "albums", album, filename)) + uploaded = col_videos.insert_one( + { + "user": current_user.user, + "album": album, + "filename": filename, + "dates": { + "uploaded": datetime.utcnow(), + "modifies": datetime.utcnow() + }, + # "location": [ + # coords["lng"], + # coords["lat"], + # coords["alt"] + # ] + } + ) return UJSONResponse( { @@ -98,7 +115,7 @@ async def video_move(id: str, album: str, current_user: User = Security(get_curr else: filename = video["filename"] - col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename}} ) + col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename, "dates.modified": datetime.utcnow()}} ) move( path.join("data", "users", current_user.user, "albums", video["album"], video["filename"]),