New secrets system and quotas (#35)
This commit is contained in:
@@ -30,6 +30,7 @@ from classes.exceptions import (
|
||||
SearchLimitInvalidError,
|
||||
SearchPageInvalidError,
|
||||
SearchTokenInvalidError,
|
||||
UserMediaQuotaReached,
|
||||
)
|
||||
from classes.models import (
|
||||
Photo,
|
||||
@@ -38,7 +39,7 @@ from classes.models import (
|
||||
SearchResultsPhoto,
|
||||
)
|
||||
from modules.app import app
|
||||
from modules.database import col_albums, col_photos, col_tokens
|
||||
from modules.database import col_albums, col_photos, col_tokens, col_videos
|
||||
from modules.exif_reader import extract_location
|
||||
from modules.hasher import get_duplicates, get_phash
|
||||
from modules.scheduler import scheduler
|
||||
@@ -91,6 +92,7 @@ async def compress_image(image_path: str):
|
||||
|
||||
|
||||
photo_post_responses = {
|
||||
403: UserMediaQuotaReached().openapi,
|
||||
404: AlbumNameNotFoundError("name").openapi,
|
||||
409: {
|
||||
"description": "Image Duplicates Found",
|
||||
@@ -125,6 +127,13 @@ async def photo_upload(
|
||||
if (await col_albums.find_one({"user": current_user.user, "name": album})) is None:
|
||||
raise AlbumNameNotFoundError(album)
|
||||
|
||||
user_media_count = (
|
||||
await col_photos.count_documents({"user": current_user.user})
|
||||
) + (await col_videos.count_documents({"user": current_user.user}))
|
||||
|
||||
if user_media_count >= current_user.quota and not current_user.quota == -1: # type: ignore
|
||||
raise UserMediaQuotaReached()
|
||||
|
||||
makedirs(Path(f"data/users/{current_user.user}/albums/{album}"), exist_ok=True)
|
||||
|
||||
filename = file.filename
|
||||
|
Reference in New Issue
Block a user