Fixed UTC time

This commit is contained in:
Profitroll 2023-01-25 16:02:28 +01:00
parent 9a48835fe4
commit e14b3e7db3
3 changed files with 13 additions and 13 deletions

View File

@ -4,7 +4,7 @@ from secrets import token_urlsafe
from shutil import move from shutil import move
from typing import List, Union from typing import List, Union
from magic import Magic from magic import Magic
from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
from os import makedirs, path, remove, system from os import makedirs, path, remove, system
from classes.models import Photo, SearchResults from classes.models import Photo, SearchResults
from modules.exif_reader import extract_location 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, "hash": file_hash,
"filename": filename, "filename": filename,
"dates": { "dates": {
"uploaded": datetime.utcnow(), "uploaded": datetime.now(tz=timezone.utc),
"modified": datetime.utcnow() "modified": datetime.now(tz=timezone.utc)
}, },
"location": [ "location": [
coords["lng"], coords["lng"],
@ -146,7 +146,7 @@ async def photo_move(id: str, album: str, current_user: User = Security(get_curr
else: else:
filename = image["filename"] 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( move(
path.join("data", "users", current_user.user, "albums", image["album"], image["filename"]), 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: except InvalidId:
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an image with such id.") 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( return UJSONResponse(
{ {

View File

@ -4,7 +4,7 @@ from secrets import token_urlsafe
from shutil import move from shutil import move
from typing import Union from typing import Union
from magic import Magic from magic import Magic
from datetime import datetime from datetime import datetime, timezone
from os import makedirs, path, remove from os import makedirs, path, remove
from classes.models import Video, SearchResults from classes.models import Video, SearchResults
#from modules.unified_exif_reader import extract_location #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, "album": album,
"filename": filename, "filename": filename,
"dates": { "dates": {
"uploaded": datetime.utcnow(), "uploaded": datetime.now(tz=timezone.utc),
"modified": datetime.utcnow() "modified": datetime.now(tz=timezone.utc)
}, },
"caption": caption, "caption": caption,
# "location": [ # "location": [
@ -118,7 +118,7 @@ async def video_move(id: str, album: str, current_user: User = Security(get_curr
else: else:
filename = video["filename"] 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( move(
path.join("data", "users", current_user.user, "albums", video["album"], video["filename"]), 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: except InvalidId:
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.") 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( return UJSONResponse(
{ {

View File

@ -1,4 +1,4 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
from typing import List, Union from typing import List, Union
from modules.database import col_users 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 ): def create_access_token( data: dict, expires_delta: Union[timedelta, None] = None ):
to_encode = data.copy() to_encode = data.copy()
if expires_delta: if expires_delta:
expire = datetime.utcnow() + expires_delta expire = datetime.now(tz=timezone.utc) + expires_delta
else: 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}) to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt return encoded_jwt