Сделана загрузка файлов
This commit is contained in:
parent
b8798a3a5a
commit
775b11d50c
3 changed files with 314 additions and 0 deletions
163
.gitignore
vendored
Normal file
163
.gitignore
vendored
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
# ---> Python
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
.pdm.toml
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
node_modules
|
49
app/main.py
Normal file
49
app/main.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
|
import string
|
||||||
|
|
||||||
|
from fastapi import FastAPI, UploadFile
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_string(length=16):
|
||||||
|
"""Генерирует случайную строку заданной длины."""
|
||||||
|
characters = string.ascii_letters + string.digits
|
||||||
|
return ''.join(random.choice(characters) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(
|
||||||
|
prefix="/api",
|
||||||
|
tags=["Сервак для загрузки"]
|
||||||
|
)
|
||||||
|
|
||||||
|
origins = ['*']
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=origins,
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||||
|
allow_headers=[
|
||||||
|
"Content-Type",
|
||||||
|
"Set-Cookie",
|
||||||
|
"Access-Control-Allow-Headers",
|
||||||
|
"Authorization",
|
||||||
|
"Accept"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
||||||
|
|
||||||
|
|
||||||
|
@app.post('/images', response_model=dict[str, str])
|
||||||
|
async def upload_images(file: UploadFile):
|
||||||
|
name = generate_random_string()
|
||||||
|
with open(f'app/static/images/{name}.webp', 'wb+') as file_object:
|
||||||
|
shutil.copyfileobj(file.file, file_object)
|
||||||
|
return {'name': name}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
102
requirements.txt
Normal file
102
requirements.txt
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
aiohttp==3.9.1
|
||||||
|
aioredis==1.3.1
|
||||||
|
aiosignal==1.3.1
|
||||||
|
alembic==1.13.1
|
||||||
|
amqp==5.2.0
|
||||||
|
annotated-types==0.6.0
|
||||||
|
anyio==4.2.0
|
||||||
|
async-timeout==4.0.3
|
||||||
|
asyncpg==0.29.0
|
||||||
|
attrs==23.2.0
|
||||||
|
autoflake==2.2.1
|
||||||
|
billiard==4.2.0
|
||||||
|
black==23.12.1
|
||||||
|
celery==5.3.6
|
||||||
|
certifi==2023.11.17
|
||||||
|
click==8.1.7
|
||||||
|
click-didyoumean==0.3.0
|
||||||
|
click-plugins==1.1.1
|
||||||
|
click-repl==0.3.0
|
||||||
|
dnspython==2.4.2
|
||||||
|
ecdsa==0.18.0
|
||||||
|
email-validator==2.1.0.post1
|
||||||
|
fastapi==0.109.0
|
||||||
|
fastapi-cache2==0.2.1
|
||||||
|
fastapi-versioning==0.10.0
|
||||||
|
flake8==7.0.0
|
||||||
|
flower==2.0.1
|
||||||
|
frozenlist==1.4.1
|
||||||
|
gevent==23.9.1
|
||||||
|
greenlet==3.0.3
|
||||||
|
gunicorn==21.2.0
|
||||||
|
h11==0.14.0
|
||||||
|
hiredis==2.3.2
|
||||||
|
httpcore==1.0.2
|
||||||
|
httptools==0.6.1
|
||||||
|
httpx==0.26.0
|
||||||
|
humanize==4.9.0
|
||||||
|
idna==3.6
|
||||||
|
iniconfig==2.0.0
|
||||||
|
isort==5.13.2
|
||||||
|
itsdangerous==2.1.2
|
||||||
|
Jinja2==3.1.3
|
||||||
|
kombu==5.3.5
|
||||||
|
Mako==1.3.0
|
||||||
|
MarkupSafe==2.1.3
|
||||||
|
mccabe==0.7.0
|
||||||
|
multidict==6.0.4
|
||||||
|
mypy-extensions==1.0.0
|
||||||
|
nodeenv==1.8.0
|
||||||
|
orjson==3.9.12
|
||||||
|
packaging==23.2
|
||||||
|
passlib==1.7.4
|
||||||
|
pathspec==0.12.1
|
||||||
|
pendulum==3.0.0
|
||||||
|
pillow==10.2.0
|
||||||
|
platformdirs==4.1.0
|
||||||
|
pluggy==1.3.0
|
||||||
|
prometheus-client==0.19.0
|
||||||
|
prometheus-fastapi-instrumentator==6.1.0
|
||||||
|
prompt-toolkit==3.0.43
|
||||||
|
pyasn1==0.5.1
|
||||||
|
pycodestyle==2.11.1
|
||||||
|
pydantic==2.6.0
|
||||||
|
pydantic-extra-types==2.5.0
|
||||||
|
pydantic-settings==2.1.0
|
||||||
|
pydantic_core==2.16.1
|
||||||
|
pyflakes==3.2.0
|
||||||
|
pyright==1.1.347
|
||||||
|
pytest==7.4.4
|
||||||
|
pytest-asyncio==0.23.3
|
||||||
|
python-dateutil==2.8.2
|
||||||
|
python-dotenv==1.0.0
|
||||||
|
python-jose==3.3.0
|
||||||
|
python-json-logger==2.0.7
|
||||||
|
python-multipart==0.0.6
|
||||||
|
pytz==2023.3.post1
|
||||||
|
PyYAML==6.0.1
|
||||||
|
redis==4.6.0
|
||||||
|
rsa==4.9
|
||||||
|
sentry-sdk==1.39.2
|
||||||
|
six==1.16.0
|
||||||
|
sniffio==1.3.0
|
||||||
|
sqladmin==0.16.0
|
||||||
|
SQLAlchemy==2.0.25
|
||||||
|
starlette==0.35.1
|
||||||
|
time-machine==2.13.0
|
||||||
|
tornado==6.4
|
||||||
|
typing_extensions==4.9.0
|
||||||
|
tzdata==2023.4
|
||||||
|
ujson==5.9.0
|
||||||
|
urllib3==2.1.0
|
||||||
|
uvicorn==0.26.0
|
||||||
|
vine==5.1.0
|
||||||
|
watchfiles==0.21.0
|
||||||
|
wcwidth==0.2.13
|
||||||
|
websockets==12.0
|
||||||
|
WTForms==3.1.2
|
||||||
|
yarl==1.9.4
|
||||||
|
zope.event==5.0
|
||||||
|
zope.interface==6.1
|
||||||
|
pywin32==305; platform_system=="Windows"
|
||||||
|
bcrypt==4.1.2; platform_system=="Windows"
|
Loading…
Add table
Reference in a new issue