notification manager
This commit is contained in:
parent
c457f37247
commit
05af84d569
@ -41,6 +41,7 @@ deploy-dev:
|
||||
DB_PASSWORD: "$DB_PASSWORD_DEMO"
|
||||
DEBUG: "true"
|
||||
TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_DEMO"
|
||||
FS_TOKEN: "$FS_TOKEN_DEV"
|
||||
|
||||
deploy-prod:
|
||||
extends:
|
||||
@ -59,3 +60,4 @@ deploy-prod:
|
||||
FS_HOST: "77.246.159.65"
|
||||
DB_PASSWORD: "$DB_PASSWORD_PROD"
|
||||
TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_PROD"
|
||||
FS_TOKEN: "$FS_TOKEN_PROD"
|
||||
|
@ -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})
|
||||
|
@ -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:
|
||||
|
@ -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())
|
||||
|
@ -9,9 +9,8 @@ class CheckersView(BaseView):
|
||||
set: Set
|
||||
|
||||
def pre_handle(self):
|
||||
self.current_set = self.set
|
||||
if (
|
||||
self.request.user != self.current_set.creator
|
||||
and self.request.user.username not in self.current_set.editors
|
||||
self.request.user != self.set.creator
|
||||
and self.request.user.username not in self.set.editors
|
||||
):
|
||||
raise AccessError()
|
||||
|
@ -28,7 +28,10 @@ class MessagingSupport(BaseCommand):
|
||||
raise NotImplementedError
|
||||
|
||||
def consume(self, ch, method, properties, body):
|
||||
self.process(json.loads(body.decode('utf-8')))
|
||||
data = json.loads(body.decode('utf-8'))
|
||||
print(f"Got {data}, processing...")
|
||||
self.process(data)
|
||||
print("Process finished successfully")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if self.queue_name is None:
|
||||
|
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import os
|
||||
from random import choice
|
||||
|
||||
from requests import get, post
|
||||
@ -9,19 +10,19 @@ from Sprint import settings
|
||||
def write_bytes(data: bytes):
|
||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/upload_file"
|
||||
print(url)
|
||||
return post(url, data=data).json()["id"]
|
||||
return post(url, data=data, headers={'token': os.getenv('FS_TOKEN')}).json()["id"]
|
||||
|
||||
|
||||
def get_bytes(num: int) -> bytes:
|
||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/get_file?id=" + str(num)
|
||||
print(url)
|
||||
return get(url).content
|
||||
return get(url, headers={'token': os.getenv('FS_TOKEN')}).content
|
||||
|
||||
|
||||
def delete_file(num: int):
|
||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/delete_file?id=" + str(num)
|
||||
print(url)
|
||||
post(url)
|
||||
post(url, headers={'token': os.getenv('FS_TOKEN')})
|
||||
|
||||
|
||||
def generate_token():
|
||||
|
@ -33,6 +33,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
@ -48,6 +49,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
volumes:
|
||||
- /sprint-data/static:/usr/src/app/static
|
||||
command: ./manage.py collectstatic --noinput
|
||||
@ -66,6 +68,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
volumes:
|
||||
- /sprint-data/static:/usr/src/app/static
|
||||
command: ./manage.py runserver 0.0.0.0:80 --noreload --insecure
|
||||
@ -90,6 +93,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
ports:
|
||||
- "5555:5555"
|
||||
volumes:
|
||||
@ -112,6 +116,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
command: ./manage.py bot
|
||||
deploy:
|
||||
mode: replicated
|
||||
@ -131,6 +136,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
command: ./manage.py loop
|
||||
deploy:
|
||||
mode: replicated
|
||||
@ -164,6 +170,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
volumes:
|
||||
- /sprint-data/solutions:/usr/src/app/solutions
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
@ -187,6 +194,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
deploy:
|
||||
mode: replicated
|
||||
replicas: 1
|
||||
@ -207,6 +215,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
deploy:
|
||||
mode: replicated
|
||||
replicas: 1
|
||||
@ -227,6 +236,7 @@ services:
|
||||
FS_HOST: $FS_HOST
|
||||
DEBUG: $DEBUG
|
||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||
FS_TOKEN: $FS_TOKEN
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
|
Loading…
Reference in New Issue
Block a user