Pridani sentry, fix mazani upravenych fotek

This commit is contained in:
Michal Kváček
2023-10-31 17:30:29 +01:00
parent 3223d2ac00
commit 0de73a5ec2
8 changed files with 51 additions and 8 deletions
@@ -0,0 +1,30 @@
"""on delete cascade u photo adjustment
Revision ID: d42172840f6c
Revises: 4996ad8bc231
Create Date: 2023-10-30 16:30:57.118694
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd42172840f6c'
down_revision = '4996ad8bc231'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('photo_adjustment_ibfk_1', 'photo_adjustment', type_='foreignkey')
op.create_foreign_key(None, 'photo_adjustment', 'photo', ['photo_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'photo_adjustment', type_='foreignkey')
op.create_foreign_key('photo_adjustment_ibfk_1', 'photo_adjustment', 'photo', ['photo_id'], ['id'])
# ### end Alembic commands ###
+2
View File
@@ -8,5 +8,7 @@ services:
restart: "always" restart: "always"
env_file: env_file:
- .env - .env
environment:
SENTRY_DSN: "https://184d1d6bd39f4fbb94804ae84e9afdd5@o472821.ingest.sentry.io/5506983"
volumes: volumes:
- ./uploads:/app/uploads - ./uploads:/app/uploads
+1
View File
@@ -22,6 +22,7 @@ services:
API_URL: "http://localhost:8000" API_URL: "http://localhost:8000"
APP_ENV: "development" APP_ENV: "development"
ALLOW_CORS_ORIGINS: "http://localhost:9000 http://localhost:9001" ALLOW_CORS_ORIGINS: "http://localhost:9000 http://localhost:9001"
SENTRY_DSN: "https://184d1d6bd39f4fbb94804ae84e9afdd5@o472821.ingest.sentry.io/5506983"
scrapy: scrapy:
+1 -1
View File
@@ -7,7 +7,7 @@ aiomysql==0.2.0
alembic==1.11.1 alembic==1.11.1
passlib==1.7.4 passlib==1.7.4
pydantic==1.10.11 # vysla uz 2.0, ale nejak mi to nefunguje pydantic==1.10.11 # vysla uz 2.0, ale nejak mi to nefunguje
sentry-sdk[fastapi]
pillow pillow
exif exif
aiocache aiocache
+7 -1
View File
@@ -2,9 +2,15 @@ import os
APP_DEBUG = True APP_DEBUG = True
GRAPHIQL = True GRAPHIQL = True
ACCESS_TOKEN_VALIDITY_MINUTES = 20
REFRESH_TOKEN_VALIDITY_DAYS = 30
API_URL = os.environ.get("API_URL") or "http://localhost:8000" API_URL = os.environ.get("API_URL") or "http://localhost:8000"
APP_SECRET_KEY = os.environ.get("APP_SECRET_KEY") or "test"
ALLOW_CORS_ORIGINS = os.environ.get("ALLOW_CORS_ORIGINS", "").split() ALLOW_CORS_ORIGINS = os.environ.get("ALLOW_CORS_ORIGINS", "").split()
SENTRY_DSN = os.environ.get("SENTRY_DSN")
APP_SECRET_KEY = os.environ.get("APP_SECRET_KEY") or "test"
if not APP_SECRET_KEY: if not APP_SECRET_KEY:
raise ValueError("Missing APP_SECRET_KEY!") raise ValueError("Missing APP_SECRET_KEY!")
+2 -2
View File
@@ -132,7 +132,7 @@ class Photo(BaseModel):
flight: Mapped['Flight'] = relationship(foreign_keys=[flight_id]) flight: Mapped['Flight'] = relationship(foreign_keys=[flight_id])
point_of_interest: Mapped['PointOfInterest'] = relationship() point_of_interest: Mapped['PointOfInterest'] = relationship()
adjustment: Mapped['PhotoAdjustment'] = relationship() adjustment: Mapped['PhotoAdjustment'] = relationship(passive_deletes=True)
created_by: Mapped['User'] = relationship() created_by: Mapped['User'] = relationship()
@@ -140,7 +140,7 @@ class PhotoAdjustment(BaseModel):
__tablename__ = "photo_adjustment" __tablename__ = "photo_adjustment"
id: Mapped[int] = mapped_column(primary_key=True) id: Mapped[int] = mapped_column(primary_key=True)
photo_id: Mapped[int] = mapped_column(Integer, ForeignKey('photo.id'), nullable=False) photo_id: Mapped[int] = mapped_column(Integer, ForeignKey('photo.id', ondelete='CASCADE'), nullable=False)
rotate: Mapped[float] = mapped_column(Float, nullable=True) rotate: Mapped[float] = mapped_column(Float, nullable=True)
contrast: Mapped[float] = mapped_column(Float, nullable=True) contrast: Mapped[float] = mapped_column(Float, nullable=True)
brightness: Mapped[float] = mapped_column(Float, nullable=True) brightness: Mapped[float] = mapped_column(Float, nullable=True)
+7 -4
View File
@@ -1,6 +1,6 @@
import sentry_sdk
from datetime import timedelta from datetime import timedelta
from typing import Optional from typing import Optional
from fastapi import FastAPI, APIRouter, Depends, Security from fastapi import FastAPI, APIRouter, Depends, Security
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearerCookie, JwtRefreshBearerCookie from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearerCookie, JwtRefreshBearerCookie
from sqlalchemy import select from sqlalchemy import select
@@ -9,7 +9,7 @@ from starlette.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse, Response from starlette.responses import RedirectResponse, Response
from starlette.staticfiles import StaticFiles from starlette.staticfiles import StaticFiles
from strawberry.fastapi import GraphQLRouter from strawberry.fastapi import GraphQLRouter
from config import APP_SECRET_KEY, GRAPHIQL, APP_DEBUG, ALLOW_CORS_ORIGINS from config import APP_SECRET_KEY, GRAPHIQL, APP_DEBUG, ALLOW_CORS_ORIGINS, SENTRY_DSN, ACCESS_TOKEN_VALIDITY_MINUTES, REFRESH_TOKEN_VALIDITY_DAYS
from database import models, async_session from database import models, async_session
from endpoints.login import LoginEndpoint, LoginInput, RefreshEndpoint, LogoutEndpoint from endpoints.login import LoginEndpoint, LoginInput, RefreshEndpoint, LogoutEndpoint
from endpoints.photo_editor_preview import PhotoEditorEndpoint from endpoints.photo_editor_preview import PhotoEditorEndpoint
@@ -22,15 +22,18 @@ class App:
access_security = JwtAccessBearerCookie( access_security = JwtAccessBearerCookie(
secret_key=APP_SECRET_KEY, secret_key=APP_SECRET_KEY,
auto_error=False, auto_error=False,
access_expires_delta=timedelta(minutes=20), access_expires_delta=timedelta(minutes=ACCESS_TOKEN_VALIDITY_MINUTES),
) )
refresh_security = JwtRefreshBearerCookie( refresh_security = JwtRefreshBearerCookie(
secret_key=APP_SECRET_KEY, secret_key=APP_SECRET_KEY,
auto_error=True, auto_error=True,
refresh_expires_delta=timedelta(days=30), refresh_expires_delta=timedelta(days=REFRESH_TOKEN_VALIDITY_DAYS),
) )
def create_app(self): def create_app(self):
if SENTRY_DSN:
sentry_sdk.init(dsn=SENTRY_DSN, enable_tracing=True)
app = FastAPI() app = FastAPI()
self.setup_exception_handlers(app) self.setup_exception_handlers(app)
+1
View File
@@ -75,6 +75,7 @@ class PhotoEditor:
return round(w), round(h) return round(w), round(h)
def rotate(self, degrees: float, crop_after_rotate: bool = False): def rotate(self, degrees: float, crop_after_rotate: bool = False):
degrees *= -1
self.img = self.img.rotate(degrees, resample=Image.Resampling.BICUBIC, expand=True) self.img = self.img.rotate(degrees, resample=Image.Resampling.BICUBIC, expand=True)
if crop_after_rotate: if crop_after_rotate: