notification manager

This commit is contained in:
Egor Matveev
2022-03-23 22:39:54 +03:00
parent c457f37247
commit 05af84d569
8 changed files with 33 additions and 7 deletions

View File

@@ -1,8 +1,11 @@
import os
from os import remove
from aiohttp import web
async def delete_file(request):
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
return web.json_response({"success": False}, status=403)
remove("data/" + request.rel_url.query['id'])
return web.json_response({"success": True})

View File

@@ -1,8 +1,12 @@
import os
import aiofiles
from aiohttp import web
async def get_file(request):
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
return web.json_response({"success": False}, status=403)
response = web.StreamResponse()
await response.prepare(request)
async with aiofiles.open("data/" + request.rel_url.query['id'], "rb") as fs:

View File

@@ -1,3 +1,5 @@
import os
from aiohttp import web
from FileStorage.sync import write_meta
@@ -5,6 +7,8 @@ import aiofiles
async def upload_file(request):
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
return web.json_response({"success": False}, status=403)
file_id = await write_meta(request)
async with aiofiles.open("data/" + str(file_id), "wb") as fs:
await fs.write(await request.content.read())