Added models where possible
This commit is contained in:
@@ -4,6 +4,7 @@ from secrets import token_urlsafe
|
||||
from magic import Magic
|
||||
from datetime import datetime
|
||||
from os import makedirs, path, remove
|
||||
from classes.models import Photo, SearchResults
|
||||
from modules.hasher import get_phash, get_duplicates
|
||||
from modules.security import User, get_current_active_user
|
||||
from modules.app import app
|
||||
@@ -15,7 +16,7 @@ from fastapi import HTTPException, UploadFile, Security
|
||||
from fastapi.responses import UJSONResponse, Response
|
||||
from starlette.status import HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST, HTTP_401_UNAUTHORIZED, HTTP_404_NOT_FOUND, HTTP_409_CONFLICT
|
||||
|
||||
@app.post("/albums/{album}/photos", response_class=UJSONResponse, description="Upload a photo to album")
|
||||
@app.post("/albums/{album}/photos", response_class=UJSONResponse, response_model=Photo, description="Upload a photo to album")
|
||||
async def photo_upload(file: UploadFile, album: str, ignore_duplicates: bool = False, current_user: User = Security(get_current_active_user, scopes=["photos.write"])):
|
||||
|
||||
if col_albums.find_one( {"user": current_user.user, "name": album} ) is None:
|
||||
@@ -91,7 +92,7 @@ async def photo_delete(id: str, current_user: User = Security(get_current_active
|
||||
|
||||
return Response(status_code=HTTP_204_NO_CONTENT)
|
||||
|
||||
@app.get("/albums/{album}/photos", response_class=UJSONResponse, description="Find a photo by filename")
|
||||
@app.get("/albums/{album}/photos", response_class=UJSONResponse, response_model=SearchResults, description="Find a photo by filename")
|
||||
async def photo_find(q: str, album: str, page: int = 1, page_size: int = 100, current_user: User = Security(get_current_active_user, scopes=["photos.list"])):
|
||||
|
||||
if col_albums.find_one( {"user": current_user.user, "name": album} ) is None:
|
||||
@@ -111,13 +112,12 @@ async def photo_find(q: str, album: str, page: int = 1, page_size: int = 100, cu
|
||||
token = str(token_urlsafe(32))
|
||||
col_tokens.insert_one( {"token": token, "query": q, "album": album, "page": page+1, "page_size": page_size, "user": pickle.dumps(current_user)} )
|
||||
output["next_page"] = f"/albums/{album}/photos/token?token={token}" # type: ignore
|
||||
|
||||
with open("something.txt", "w", encoding="utf-8") as f:
|
||||
f.write(pickle.loads(pickle.dumps(current_user)).user)
|
||||
else:
|
||||
output["next_page"] = None # type: ignore
|
||||
|
||||
return UJSONResponse(output)
|
||||
|
||||
@app.get("/albums/{album}/photos/token", response_class=UJSONResponse, description="Find a photo by token")
|
||||
@app.get("/albums/{album}/photos/token", response_class=UJSONResponse, response_model=SearchResults, description="Find a photo by token")
|
||||
async def photo_find_token(token: str):
|
||||
|
||||
found_record = col_tokens.find_one( {"token": token} )
|
||||
|
Reference in New Issue
Block a user