Мелкие правки констант

This commit is contained in:
urec56 2024-03-23 21:35:54 +03:00
parent 447a0bec87
commit 42d185292b
3 changed files with 16 additions and 16 deletions

View file

@ -1,9 +1,9 @@
aws_access_key_id= AWS_ACCESS_KEY_ID=
aws_secret_access_key= AWS_SECRET_ACCESS_KEY=
bucket_name= BUCKET_NAME=
s3_endpoint_url= S3_ENDPOINT_URL=
region_name= REGION_NAME=
REDIS_HOST= REDIS_HOST=
REDIS_PORT= REDIS_PORT=

View file

@ -5,12 +5,12 @@ from pydantic_settings import BaseSettings
class Settings(BaseSettings): class Settings(BaseSettings):
model_config = ConfigDict(env_file=".env") model_config = ConfigDict(env_file=".env")
aws_access_key_id: str AWS_ACCESS_KEY_ID: str
aws_secret_access_key: str AWS_SECRET_ACCESS_KEY: str
bucket_name: str BUCKET_NAME: str
s3_endpoint_url: str S3_ENDPOINT_URL: str
region_name: str REGION_NAME: str
REDIS_HOST: str REDIS_HOST: str
REDIS_PORT: int REDIS_PORT: int

View file

@ -34,10 +34,10 @@ app.add_middleware(
) )
s3 = boto3.client('s3', s3 = boto3.client('s3',
endpoint_url=settings.s3_endpoint_url, endpoint_url=settings.S3_ENDPOINT_URL,
region_name=settings.region_name, region_name=settings.REGION_NAME,
aws_access_key_id=settings.aws_access_key_id, aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.aws_secret_access_key) aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY)
@app.post("/upload_image", response_model=SImage) @app.post("/upload_image", response_model=SImage)
@ -66,14 +66,14 @@ async def upload_image(file: UploadFile, target_width: int = 250):
object_key = str(uuid.uuid4()) + f".{image_type}" object_key = str(uuid.uuid4()) + f".{image_type}"
try: try:
post = s3.generate_presigned_post(settings.bucket_name, object_key, post = s3.generate_presigned_post(settings.BUCKET_NAME, object_key,
Fields={"Content-Type": "image/webp"}, Fields={"Content-Type": "image/webp"},
Conditions=[["eq", "$content-type", "image/webp"]]) Conditions=[["eq", "$content-type", "image/webp"]])
async with AsyncClient() as ac: async with AsyncClient() as ac:
await ac.post(post["url"], data=post["fields"], files=[("file", (object_key, new_image))]) await ac.post(post["url"], data=post["fields"], files=[("file", (object_key, new_image))])
response = s3.generate_presigned_url('get_object', response = s3.generate_presigned_url('get_object',
Params={'Bucket': settings.bucket_name, Params={'Bucket': settings.BUCKET_NAME,
'Key': object_key}, 'Key': object_key},
ExpiresIn=36000) ExpiresIn=36000)