Изменил бекграунды
This commit is contained in:
parent
f5ba50e65e
commit
cdf4aae867
1 changed files with 13 additions and 11 deletions
24
app/main.py
24
app/main.py
|
@ -1,10 +1,12 @@
|
|||
import random
|
||||
import shutil
|
||||
import string
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, UploadFile
|
||||
from fastapi import FastAPI, UploadFile, Query
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def generate_random_string(length=16):
|
||||
|
@ -46,16 +48,6 @@ async def upload_avatar(file: UploadFile):
|
|||
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)
|
||||
|
@ -63,3 +55,13 @@ async def upload_image(file: UploadFile):
|
|||
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=list[str])
|
||||
async def upload_background(file: UploadFile):
|
||||
name = generate_random_string()
|
||||
image_url = f'static/images/backgrounds/{name}_background.png'
|
||||
with open('app/' + image_url, 'wb+') as file_object:
|
||||
shutil.copyfileobj(file.file, file_object)
|
||||
backgrounds = ['static/images/backgrounds/' + background for background in os.listdir('app/static/images/backgrounds')]
|
||||
return backgrounds
|
||||
|
|
Loading…
Add table
Reference in a new issue