From e14b3e7db3a2b8ad87804632154b5d2f62d88b63 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 25 Jan 2023 16:02:28 +0100 Subject: [PATCH] Fixed UTC time --- extensions/photos.py | 10 +++++----- extensions/videos.py | 10 +++++----- modules/security.py | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/extensions/photos.py b/extensions/photos.py index baf26da..acd02ce 100644 --- a/extensions/photos.py +++ b/extensions/photos.py @@ -4,7 +4,7 @@ from secrets import token_urlsafe from shutil import move from typing import List, Union from magic import Magic -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from os import makedirs, path, remove, system from classes.models import Photo, SearchResults from modules.exif_reader import extract_location @@ -84,8 +84,8 @@ async def photo_upload(file: UploadFile, album: str, ignore_duplicates: bool = F "hash": file_hash, "filename": filename, "dates": { - "uploaded": datetime.utcnow(), - "modified": datetime.utcnow() + "uploaded": datetime.now(tz=timezone.utc), + "modified": datetime.now(tz=timezone.utc) }, "location": [ coords["lng"], @@ -146,7 +146,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, "dates.modified": datetime.utcnow()}} ) + col_photos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename, "dates.modified": datetime.now(tz=timezone.utc)}} ) move( path.join("data", "users", current_user.user, "albums", image["album"], image["filename"]), @@ -170,7 +170,7 @@ async def photo_patch(id: str, caption: str, current_user: User = Security(get_c except InvalidId: return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an image with such id.") - col_photos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"caption": caption, "dates.modified": datetime.utcnow()}} ) + col_photos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"caption": caption, "dates.modified": datetime.now(tz=timezone.utc)}} ) return UJSONResponse( { diff --git a/extensions/videos.py b/extensions/videos.py index 80a0392..d35e1c0 100644 --- a/extensions/videos.py +++ b/extensions/videos.py @@ -4,7 +4,7 @@ from secrets import token_urlsafe from shutil import move from typing import Union from magic import Magic -from datetime import datetime +from datetime import datetime, timezone from os import makedirs, path, remove from classes.models import Video, SearchResults #from modules.unified_exif_reader import extract_location @@ -60,8 +60,8 @@ async def video_upload(file: UploadFile, album: str, caption: Union[str, None] = "album": album, "filename": filename, "dates": { - "uploaded": datetime.utcnow(), - "modified": datetime.utcnow() + "uploaded": datetime.now(tz=timezone.utc), + "modified": datetime.now(tz=timezone.utc) }, "caption": caption, # "location": [ @@ -118,7 +118,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, "dates.modified": datetime.utcnow()}} ) + col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"album": album, "filename": filename, "dates.modified": datetime.now(tz=timezone.utc)}} ) move( path.join("data", "users", current_user.user, "albums", video["album"], video["filename"]), @@ -142,7 +142,7 @@ async def video_patch(id: str, caption: str, current_user: User = Security(get_c except InvalidId: return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.") - col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"caption": caption, "dates.modified": datetime.utcnow()}} ) + col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"caption": caption, "dates.modified": datetime.now(tz=timezone.utc)}} ) return UJSONResponse( { diff --git a/modules/security.py b/modules/security.py index 3932e28..4ccd324 100644 --- a/modules/security.py +++ b/modules/security.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import List, Union from modules.database import col_users @@ -82,9 +82,9 @@ def authenticate_user(user_name: str, password: str): def create_access_token( data: dict, expires_delta: Union[timedelta, None] = None ): to_encode = data.copy() if expires_delta: - expire = datetime.utcnow() + expires_delta + expire = datetime.now(tz=timezone.utc) + expires_delta else: - expire = datetime.utcnow() + timedelta(days=ACCESS_TOKEN_EXPIRE_DAYS) + expire = datetime.now(tz=timezone.utc) + timedelta(days=ACCESS_TOKEN_EXPIRE_DAYS) to_encode.update({"exp": expire}) encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) return encoded_jwt