Refactor
This commit is contained in:
parent
85d23c8c95
commit
a487c3163e
123
.gitignore
vendored
Normal file
123
.gitignore
vendored
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
|
||||||
|
# Created by https://www.gitignore.io/api/python,virtualenv
|
||||||
|
# Edit at https://www.gitignore.io/?templates=python,virtualenv
|
||||||
|
|
||||||
|
### 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/
|
||||||
|
pip-wheel-metadata/
|
||||||
|
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
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.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
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# Mr Developer
|
||||||
|
.mr.developer.cfg
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
### VirtualEnv ###
|
||||||
|
# Virtualenv
|
||||||
|
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
||||||
|
pyvenv.cfg
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
pip-selfcheck.json
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/python,virtualenv
|
@ -6,20 +6,23 @@ routes.static('/static', 'static')
|
|||||||
|
|
||||||
admintoken = "ae33fd8cc4fdcb1ff50ba42ff48046a7"
|
admintoken = "ae33fd8cc4fdcb1ff50ba42ff48046a7"
|
||||||
|
|
||||||
|
CLIENT_REGEX = r'/{client:[a-zA-Z0-9]{16}}'
|
||||||
|
|
||||||
meta_dict = {}
|
meta_dict = {}
|
||||||
|
|
||||||
@routes.get(r'/{client:[a-z][a-z][a-z][a-z][a-z]}')
|
|
||||||
|
@routes.get(CLIENT_REGEX)
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
#session = request.match_info.get("session", "")
|
|
||||||
client = request.match_info.get("client", "")
|
client = request.match_info.get("client", "")
|
||||||
print(f"{client=} accessed")
|
print(f"{client=} accessed")
|
||||||
return aiohttp.web.FileResponse('static/ui.html')
|
return aiohttp.web.FileResponse('ui.html')
|
||||||
|
|
||||||
|
|
||||||
async def handle_request(data, client):
|
async def handle_request(data, client):
|
||||||
return "foo" in data
|
return "foo" in data
|
||||||
|
|
||||||
@routes.post('/{client}/api')
|
|
||||||
|
@routes.post(CLIENT_REGEX + '/api')
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
client = request.match_info.get("client", "")
|
client = request.match_info.get("client", "")
|
||||||
|
|
||||||
@ -27,19 +30,21 @@ async def handler(request):
|
|||||||
|
|
||||||
ok = await handle_request(data, client)
|
ok = await handle_request(data, client)
|
||||||
if ok:
|
if ok:
|
||||||
#return aiohttp.web.json_response({"x" : x})
|
# return aiohttp.web.json_response({"x" : x})
|
||||||
return aiohttp.web.Response(status=200)
|
return aiohttp.web.Response(status=200)
|
||||||
else:
|
else:
|
||||||
return aiohttp.web.Response(status=400)
|
return aiohttp.web.Response(status=400)
|
||||||
|
|
||||||
|
|
||||||
@routes.get(f"/api/{admintoken}")
|
@routes.get(f"/api/{admintoken}")
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
return aiohttp.web.json_response(meta_dict)
|
return aiohttp.web.json_response(meta_dict)
|
||||||
|
|
||||||
|
|
||||||
@routes.get('/')
|
@routes.get('/')
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
del request # unused
|
del request # unused
|
||||||
return aiohttp.web.FileResponse('static/index.html')
|
return aiohttp.web.FileResponse('index.html')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
aiohttp==3.6.2
|
Loading…
Reference in New Issue
Block a user