Pridan nginx pro servirovani statickych souboru, uprava fotek
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
server {
|
||||||
|
listen 8999;
|
||||||
|
listen [::]:8999;
|
||||||
|
|
||||||
|
root /app/uploads;
|
||||||
|
gzip_static on;
|
||||||
|
}
|
||||||
@@ -17,5 +17,14 @@ services:
|
|||||||
- 8000:8000
|
- 8000:8000
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
image: nginx:alpine
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./config/nginx.dev.yml:/etc/nginx/conf.d/app-dev.conf
|
||||||
|
- ./uploads:/app/uploads
|
||||||
|
ports:
|
||||||
|
- "8999:8999"
|
||||||
volumes:
|
volumes:
|
||||||
db-data: { }
|
db-data: { }
|
||||||
@@ -128,6 +128,4 @@ class EditFlightMutation:
|
|||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
async def edit_flight(self, info, id: int, input: EditFlightInput) -> Flight:
|
async def edit_flight(self, info, id: int, input: EditFlightInput) -> Flight:
|
||||||
input_data = input.to_dict()
|
return await models.Flight.update(info.context.db, id=id, data=input.to_dict())
|
||||||
|
|
||||||
return await models.Flight.update(info.context.db, id=id, data=input_data)
|
|
||||||
|
|||||||
@@ -4,13 +4,17 @@ from sqlalchemy import select
|
|||||||
from strawberry.file_uploads import Upload
|
from strawberry.file_uploads import Upload
|
||||||
from database import models
|
from database import models
|
||||||
from graphql_schema.sqlalchemy_to_strawberry_type import strawberry_sqlalchemy_type, strawberry_sqlalchemy_input
|
from graphql_schema.sqlalchemy_to_strawberry_type import strawberry_sqlalchemy_type, strawberry_sqlalchemy_input
|
||||||
from upload_utils import get_public_url, handle_file_upload
|
from upload_utils import get_public_url, handle_file_upload, delete_file
|
||||||
|
|
||||||
|
|
||||||
@strawberry_sqlalchemy_type(models.Photo)
|
@strawberry_sqlalchemy_type(models.Photo)
|
||||||
class Photo:
|
class Photo:
|
||||||
url: str = strawberry.field(resolver=lambda root: get_public_url(root.filename))
|
url: str = strawberry.field(
|
||||||
thumbnail_url: str = strawberry.field(resolver=lambda root: get_public_url(f"thumbs/{root.filename}"))
|
resolver=lambda root: get_public_url(f"photos/{root.flight_id}/{root.filename}")
|
||||||
|
)
|
||||||
|
thumbnail_url: str = strawberry.field(
|
||||||
|
resolver=lambda root: get_public_url(f"photos/{root.flight_id}/{root.filename}") # TODO: doplnit thumb!
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_base_query(user_id: int):
|
def get_base_query(user_id: int):
|
||||||
@@ -21,6 +25,10 @@ def get_base_query(user_id: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_photo_basepath(flight_id: int) -> str:
|
||||||
|
return f"/app/uploads/photos/{flight_id}"
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class PhotoQueries:
|
class PhotoQueries:
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
@@ -37,8 +45,7 @@ class UploadPhotoMutation:
|
|||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
async def upload_photo(self, info, input: UploadPhotoInput) -> Photo:
|
async def upload_photo(self, info, input: UploadPhotoInput) -> Photo:
|
||||||
photos_dest = f"/app/uploads/photos/{input.flight_id}/"
|
filename = await handle_file_upload(input.photo, get_photo_basepath(input.flight_id))
|
||||||
filename = await handle_file_upload(input.photo, photos_dest)
|
|
||||||
|
|
||||||
# todo: udelat nahled do thumbs slozky
|
# todo: udelat nahled do thumbs slozky
|
||||||
|
|
||||||
@@ -55,27 +62,32 @@ class UploadPhotoMutation:
|
|||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class EditPhotoMutation:
|
class EditPhotoMutation:
|
||||||
@strawberry_sqlalchemy_input(models.Photo, exclude_fields=[], all_optional=True)
|
@strawberry_sqlalchemy_input(models.Photo, exclude_fields=["id"], all_optional=True)
|
||||||
class EditPhotoInput:
|
class EditPhotoInput:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
async def update_photo(self, info, input: EditPhotoInput) -> Photo:
|
async def edit_photo(self, info, id: int, input: EditPhotoInput) -> Photo:
|
||||||
query = get_base_query(info.context.user_id)
|
query = get_base_query(info.context.user_id)
|
||||||
photo = info.context.db.scalars(query.filter(models.Photo.id == input.id))
|
photo = (await info.context.db.scalars(query.filter(models.Photo.id == id))).one()
|
||||||
|
|
||||||
update_data = input.to_dict()
|
return await models.Photo.update(info.context.db, obj=photo, data=input.to_dict())
|
||||||
photo.update(**update_data)
|
|
||||||
|
|
||||||
return photo
|
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class DeletePhotoMutation:
|
class DeletePhotoMutation:
|
||||||
@strawberry.input
|
|
||||||
class DeletePhotoInput:
|
|
||||||
id: int
|
|
||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
async def delete_photo(self, info, input: DeletePhotoInput) -> Photo:
|
async def delete_photo(self, info, id: int) -> Photo:
|
||||||
pass
|
query = get_base_query(info.context.user_id)
|
||||||
|
photo = (await info.context.db.scalars(query.filter(models.Photo.id == id))).one()
|
||||||
|
|
||||||
|
base_path = get_photo_basepath(photo.flight_id)
|
||||||
|
try:
|
||||||
|
delete_file(f"{base_path}/{photo.filename}")
|
||||||
|
# TODO: odstranit nahledy
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR", e)
|
||||||
|
|
||||||
|
await info.context.db.delete(photo)
|
||||||
|
|
||||||
|
return photo
|
||||||
|
|||||||
+1
-2
@@ -1,12 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from strawberry.file_uploads import Upload
|
from strawberry.file_uploads import Upload
|
||||||
|
|
||||||
|
|
||||||
def get_public_url(filename: Optional[str]):
|
def get_public_url(filename: Optional[str]):
|
||||||
return f"http://localhost:8000/uploads/{filename}" if filename else None
|
return f"http://localhost:8999/{filename}" if filename else None
|
||||||
|
|
||||||
|
|
||||||
def check_directories(path: str):
|
def check_directories(path: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user