Добавил новые эндпоинты для загрузки

This commit is contained in:
urec56 2024-02-17 12:05:00 +03:00
parent 637f0401da
commit 78d7b3a412
3 changed files with 32 additions and 4 deletions

7
.dockerignore Normal file
View file

@ -0,0 +1,7 @@
.venv
.idea
.gitignore
bp/
app/static/images/images/
app/static/images/backgrounds/
app/static/images/avatars/

8
.gitignore vendored
View file

@ -161,4 +161,10 @@ cython_debug/
.idea/
node_modules
.env_non_dev
.env_non_dev
bp/
app/static/images/images/
app/static/images/backgrounds/
app/static/images/avatars/

View file

@ -37,14 +37,29 @@ app.add_middleware(
app.mount("/static", StaticFiles(directory="app/static"), name="static")
@app.post('/images', response_model=dict[str, str])
async def upload_images(file: UploadFile):
@app.post('/upload_avatar', response_model=dict[str, str])
async def upload_avatar(file: UploadFile):
name = generate_random_string()
image_url = f'static/images/{name}_avatar.png'
image_url = f'static/images/avatars/{name}_avatar.png'
with open('app/' + image_url, 'wb+') as file_object:
shutil.copyfileobj(file.file, file_object)
return {'image_url': image_url}
@app.post('/upload_background', response_model=dict[str, str])
async def upload_background(file: UploadFile):
name = file.filename.split('.')[0]
file_format = file.filename.split('.')[-1]
image_url = f'static/images/backgrounds/{name}_background.{file_format}'
with open('app/' + image_url, 'wb+') as file_object:
shutil.copyfileobj(file.file, file_object)
return {'image_url': image_url}
@app.post('/upload_image', response_model=dict[str, str])
async def upload_image(file: UploadFile):
name = generate_random_string(50)
image_url = f'static/images/images/{name}_image.png'
with open('app/' + image_url, 'wb+') as file_object:
shutil.copyfileobj(file.file, file_object)
return {'image_url': image_url}