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