Fixes and cleanups #11

Merged
profitroll merged 7 commits from dev into master 2023-06-22 14:52:23 +03:00
14 changed files with 82 additions and 97 deletions
Showing only changes of commit 83dd4b6746 - Show all commits

View File

@ -1,4 +1,5 @@
from typing import List, Union from typing import List, Union
from pydantic import BaseModel from pydantic import BaseModel

View File

@ -1,7 +1,5 @@
from fastapi import Request from fastapi import Request
from fastapi.responses import UJSONResponse from fastapi.responses import UJSONResponse
from modules.app import app
from classes.exceptions import *
from starlette.status import ( from starlette.status import (
HTTP_400_BAD_REQUEST, HTTP_400_BAD_REQUEST,
HTTP_401_UNAUTHORIZED, HTTP_401_UNAUTHORIZED,
@ -11,6 +9,9 @@ from starlette.status import (
HTTP_422_UNPROCESSABLE_ENTITY, HTTP_422_UNPROCESSABLE_ENTITY,
) )
from classes.exceptions import *
from modules.app import app
@app.exception_handler(AlbumNotFoundError) @app.exception_handler(AlbumNotFoundError)
async def album_not_found_exception_handler(request: Request, exc: AlbumNotFoundError): async def album_not_found_exception_handler(request: Request, exc: AlbumNotFoundError):

View File

@ -1,8 +1,10 @@
import aiofiles
from os import path from os import path
from modules.app import app
import aiofiles
from fastapi.responses import HTMLResponse, Response from fastapi.responses import HTMLResponse, Response
from modules.app import app
@app.get("/pages/matter.css", include_in_schema=False) @app.get("/pages/matter.css", include_in_schema=False)
async def page_matter(): async def page_matter():

View File

@ -1,54 +1,41 @@
import aiofiles
import re
import pickle import pickle
import re
from datetime import datetime, timedelta, timezone
from os import makedirs, path, remove, system
from secrets import token_urlsafe from secrets import token_urlsafe
from shutil import move from shutil import move
from threading import Thread from threading import Thread
from typing import Union from typing import Union
from uuid import uuid4 from uuid import uuid4
from magic import Magic
from datetime import datetime, timedelta, timezone
from os import makedirs, path, remove, system
import aiofiles
from bson.errors import InvalidId
from bson.objectid import ObjectId
from fastapi import Security, UploadFile
from fastapi.exceptions import HTTPException
from fastapi.responses import Response, UJSONResponse
from jose import JWTError, jwt
from magic import Magic
from plum.exceptions import UnpackError
from pydantic import ValidationError from pydantic import ValidationError
from classes.exceptions import ( from pymongo import DESCENDING
AccessTokenInvalidError, from starlette.status import (HTTP_204_NO_CONTENT, HTTP_401_UNAUTHORIZED,
AlbumNameNotFoundError, HTTP_409_CONFLICT)
PhotoNotFoundError,
from classes.exceptions import (AccessTokenInvalidError,
AlbumNameNotFoundError, PhotoNotFoundError,
PhotoSearchQueryEmptyError, PhotoSearchQueryEmptyError,
SearchPageInvalidError, SearchPageInvalidError,
SearchTokenInvalidError, SearchTokenInvalidError)
)
from classes.models import Photo, PhotoPublic, SearchResultsPhoto from classes.models import Photo, PhotoPublic, SearchResultsPhoto
from modules.exif_reader import extract_location
from modules.hasher import get_phash, get_duplicates
from modules.scheduler import scheduler
from modules.security import (
ALGORITHM,
SECRET_KEY,
TokenData,
User,
create_access_token,
get_current_active_user,
get_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_albums, col_photos, col_tokens
from pymongo import DESCENDING from modules.exif_reader import extract_location
from bson.objectid import ObjectId from modules.hasher import get_duplicates, get_phash
from bson.errors import InvalidId from modules.scheduler import scheduler
from plum.exceptions import UnpackError from modules.security import (ALGORITHM, SECRET_KEY, TokenData, User,
from jose import JWTError, jwt create_access_token, get_current_active_user,
get_user)
from fastapi import UploadFile, Security
from fastapi.responses import UJSONResponse, Response
from fastapi.exceptions import HTTPException
from starlette.status import (
HTTP_204_NO_CONTENT,
HTTP_401_UNAUTHORIZED,
HTTP_409_CONFLICT,
)
from modules.utils import configGet, logWrite from modules.utils import configGet, logWrite

View File

@ -1,12 +1,10 @@
from datetime import timedelta from datetime import timedelta
from classes.exceptions import UserCredentialsInvalid
from modules.app import app
from fastapi import Depends from fastapi import Depends
from fastapi.security import ( from fastapi.security import OAuth2PasswordRequestForm
OAuth2PasswordRequestForm,
)
from classes.exceptions import UserCredentialsInvalid
from modules.app import app
from modules.security import ( from modules.security import (
ACCESS_TOKEN_EXPIRE_DAYS, ACCESS_TOKEN_EXPIRE_DAYS,
Token, Token,

View File

@ -1,27 +1,19 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from uuid import uuid1
from fastapi import Depends, Form
from fastapi.responses import Response, UJSONResponse
from starlette.status import HTTP_204_NO_CONTENT
from classes.exceptions import ( from classes.exceptions import (
UserAlreadyExists, UserAlreadyExists,
UserCredentialsInvalid, UserCredentialsInvalid,
UserEmailCodeInvalid, UserEmailCodeInvalid,
) )
from modules.database import (
col_users,
col_albums,
col_photos,
col_emails,
col_videos,
col_emails,
)
from modules.app import app from modules.app import app
from modules.utils import configGet, logWrite from modules.database import col_albums, col_emails, col_photos, col_users, col_videos
from modules.scheduler import scheduler
from modules.mailer import mail_sender from modules.mailer import mail_sender
from modules.scheduler import scheduler
from uuid import uuid1
from fastapi import Depends, Form
from fastapi.responses import Response, UJSONResponse
from starlette.status import HTTP_204_NO_CONTENT
from modules.security import ( from modules.security import (
User, User,
get_current_active_user, get_current_active_user,
@ -29,6 +21,7 @@ from modules.security import (
get_user, get_user,
verify_password, verify_password,
) )
from modules.utils import configGet, logWrite
async def send_confirmation(user: str, email: str): async def send_confirmation(user: str, email: str):

View File

@ -1,12 +1,20 @@
import aiofiles
import re
import pickle import pickle
import re
from datetime import datetime, timezone
from os import makedirs, path, remove
from secrets import token_urlsafe from secrets import token_urlsafe
from shutil import move from shutil import move
from typing import Union from typing import Union
import aiofiles
from bson.errors import InvalidId
from bson.objectid import ObjectId
from fastapi import Security, UploadFile
from fastapi.responses import Response, UJSONResponse
from magic import Magic from magic import Magic
from datetime import datetime, timezone from pymongo import DESCENDING
from os import makedirs, path, remove from starlette.status import HTTP_204_NO_CONTENT
from classes.exceptions import ( from classes.exceptions import (
AlbumNameNotFoundError, AlbumNameNotFoundError,
SearchPageInvalidError, SearchPageInvalidError,
@ -14,17 +22,10 @@ from classes.exceptions import (
VideoNotFoundError, VideoNotFoundError,
VideoSearchQueryEmptyError, VideoSearchQueryEmptyError,
) )
from classes.models import Video, SearchResultsVideo, VideoPublic from classes.models import SearchResultsVideo, Video, VideoPublic
from modules.security import User, get_current_active_user
from modules.app import app from modules.app import app
from modules.database import col_videos, col_albums, col_tokens from modules.database import col_albums, col_tokens, col_videos
from bson.objectid import ObjectId from modules.security import User, get_current_active_user
from bson.errors import InvalidId
from pymongo import DESCENDING
from fastapi import UploadFile, Security
from fastapi.responses import UJSONResponse, Response
from starlette.status import HTTP_204_NO_CONTENT
video_post_responses = {404: AlbumNameNotFoundError("name").openapi} video_post_responses = {404: AlbumNameNotFoundError("name").openapi}

View File

@ -1,6 +1,5 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
app = FastAPI(title="END PLAY Photos", docs_url=None, redoc_url=None, version="0.2") app = FastAPI(title="END PLAY Photos", docs_url=None, redoc_url=None, version="0.2")

View File

@ -1,5 +1,6 @@
from pymongo import GEOSPHERE, MongoClient
from modules.utils import configGet from modules.utils import configGet
from pymongo import MongoClient, GEOSPHERE
db_config = configGet("database") db_config = configGet("database")

View File

@ -1,8 +1,9 @@
from modules.database import col_photos import cv2
import numpy as np import numpy as np
from numpy.typing import NDArray from numpy.typing import NDArray
from scipy import spatial from scipy import spatial
import cv2
from modules.database import col_photos
def hash_array_to_hash_hex(hash_array): def hash_array_to_hash_hex(hash_array):

View File

@ -1,6 +1,7 @@
from smtplib import SMTP, SMTP_SSL from smtplib import SMTP, SMTP_SSL
from traceback import print_exc
from ssl import create_default_context from ssl import create_default_context
from traceback import print_exc
from modules.utils import configGet, logWrite from modules.utils import configGet, logWrite
try: try:

View File

@ -1,16 +1,13 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from typing import List, Union from typing import List, Union
from modules.database import col_users
from fastapi import Depends, HTTPException, Security, status from fastapi import Depends, HTTPException, Security, status
from fastapi.security import ( from fastapi.security import OAuth2PasswordBearer, SecurityScopes
OAuth2PasswordBearer,
SecurityScopes,
)
from jose import JWTError, jwt from jose import JWTError, jwt
from passlib.context import CryptContext from passlib.context import CryptContext
from pydantic import BaseModel, ValidationError from pydantic import BaseModel, ValidationError
from modules.database import col_users
with open("secret_key", "r", encoding="utf-8") as f: with open("secret_key", "r", encoding="utf-8") as f:
SECRET_KEY = f.read() SECRET_KEY = f.read()

View File

@ -1,6 +1,7 @@
from typing import Any, Union
from ujson import loads, dumps, JSONDecodeError
from traceback import print_exc from traceback import print_exc
from typing import Any, Union
from ujson import JSONDecodeError, dumps, loads
# Print to stdout and then to log # Print to stdout and then to log

View File

@ -1,10 +1,12 @@
from os import makedirs, path from os import makedirs, path
from modules.app import app
from modules.utils import *
from modules.scheduler import scheduler
from modules.extensions_loader import dynamic_import_from_src
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from modules.app import app
from modules.extensions_loader import dynamic_import_from_src
from modules.scheduler import scheduler
from modules.utils import *
makedirs(path.join("data", "users"), exist_ok=True) makedirs(path.join("data", "users"), exist_ok=True)