Compare commits
2 commits
f5ba50e65e
...
6a8eed7a07
Author | SHA1 | Date | |
---|---|---|---|
6a8eed7a07 | |||
cdf4aae867 |
3 changed files with 14 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
.venv
|
.venv
|
||||||
.idea
|
.idea
|
||||||
.gitignore
|
.gitignore
|
||||||
|
.git
|
||||||
bp/images/*
|
bp/images/*
|
||||||
bp/backgrounds/*
|
bp/backgrounds/*
|
||||||
bp/avatars/*
|
bp/avatars/*
|
||||||
|
|
24
app/main.py
24
app/main.py
|
@ -1,10 +1,12 @@
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
|
import os
|
||||||
|
|
||||||
from fastapi import FastAPI, UploadFile
|
from fastapi import FastAPI, UploadFile, Query
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
def generate_random_string(length=16):
|
def generate_random_string(length=16):
|
||||||
|
@ -46,16 +48,6 @@ async def upload_avatar(file: UploadFile):
|
||||||
return {'image_url': image_url}
|
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])
|
@app.post('/upload_image', response_model=dict[str, str])
|
||||||
async def upload_image(file: UploadFile):
|
async def upload_image(file: UploadFile):
|
||||||
name = generate_random_string(50)
|
name = generate_random_string(50)
|
||||||
|
@ -63,3 +55,13 @@ async def upload_image(file: UploadFile):
|
||||||
with open('app/' + image_url, 'wb+') as file_object:
|
with open('app/' + image_url, 'wb+') as file_object:
|
||||||
shutil.copyfileobj(file.file, file_object)
|
shutil.copyfileobj(file.file, file_object)
|
||||||
return {'image_url': image_url}
|
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
|
||||||
|
|
|
@ -7,6 +7,5 @@ services:
|
||||||
container_name: uploader_server
|
container_name: uploader_server
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:55555:8000
|
- 127.0.0.1:55555:8000
|
||||||
restart: always
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./bp:/BP/app/static/images
|
- ./bp:/BP/app/static/images
|
||||||
|
|
Loading…
Add table
Reference in a new issue