mirror of
https://github.com/qwerfd2/Groove_Coaster_2_Server.git
synced 2026-10-13 09:38:23 +03:00
Push
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from starlette.responses import HTMLResponse
|
||||
from starlette.requests import Request
|
||||
from starlette.routing import Route
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
|
||||
from api.database import database, batch_token
|
||||
from config import THREAD_COUNT
|
||||
|
||||
async def batch_handler(request: Request):
|
||||
data = await request.json()
|
||||
token = data.get("token")
|
||||
platform = data.get("platform")
|
||||
if not token:
|
||||
return HTMLResponse(content=json.dumps({"error": "Token is required"}), status_code=400)
|
||||
|
||||
if platform not in ["Android", "iOS"]:
|
||||
return HTMLResponse(content=json.dumps({"error": "Invalid platform"}), status_code=400)
|
||||
|
||||
query = batch_token.select().where(batch_token.c.token == token)
|
||||
result = await database.fetch_one(query)
|
||||
|
||||
if result['expire_at'] < int(time.time()):
|
||||
return HTMLResponse(content=json.dumps({"error": "Token expired"}), status_code=400)
|
||||
|
||||
with open(os.path.join('api/config/', 'download_manifest.json'), 'r', encoding='utf-8') as f:
|
||||
stage_manifest = json.load(f)
|
||||
|
||||
if platform == "Android":
|
||||
with open(os.path.join('api/config/', 'download_manifest_android.json'), 'r', encoding='utf-8') as f:
|
||||
audio_manifest = json.load(f)
|
||||
else:
|
||||
with open(os.path.join('api/config/', 'download_manifest_ios.json'), 'r', encoding='utf-8') as f:
|
||||
audio_manifest = json.load(f)
|
||||
|
||||
download_manifest = {
|
||||
"stage": stage_manifest,
|
||||
"audio": audio_manifest,
|
||||
"thread": THREAD_COUNT
|
||||
}
|
||||
|
||||
return HTMLResponse(content=json.dumps(download_manifest), status_code=200)
|
||||
|
||||
routes = [
|
||||
Route("/batch", batch_handler, methods=["POST"]),
|
||||
]
|
||||
+16
-6
@@ -8,6 +8,8 @@ from config import REDIS_ADDRESS, USE_REDIS_CACHE
|
||||
import os
|
||||
import databases
|
||||
import datetime
|
||||
import time
|
||||
|
||||
if USE_REDIS_CACHE:
|
||||
import redis.asyncio as aioredis
|
||||
|
||||
@@ -83,6 +85,17 @@ blacklist = Table(
|
||||
Column("reason", String(256))
|
||||
)
|
||||
|
||||
batch_token = Table(
|
||||
"batch_token",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, autoincrement=True),
|
||||
Column("token", String(512), nullable=False, unique=True),
|
||||
Column("sid", Integer, nullable=False),
|
||||
Column("verification_name", String(64), nullable=False, default=False),
|
||||
Column("verification_id", String(64), nullable=False),
|
||||
Column("expire_at", Integer, default=int(time.time()) + 1800),
|
||||
)
|
||||
|
||||
async def init_db():
|
||||
global redis
|
||||
if not os.path.exists(DB_PATH):
|
||||
@@ -102,8 +115,7 @@ async def init_db():
|
||||
|
||||
async def get_user_data(uid, data_field):
|
||||
query = select(user.c[data_field]).where(user.c.device_id == uid[b'vid'][0].decode())
|
||||
async with database.transaction():
|
||||
result = await database.fetch_one(query)
|
||||
result = await database.fetch_one(query)
|
||||
return result[data_field] if result else None
|
||||
|
||||
async def set_user_data(uid, data_field, new_data):
|
||||
@@ -117,8 +129,7 @@ async def set_user_data(uid, data_field, new_data):
|
||||
|
||||
async def check_whitelist(uid):
|
||||
query = select(whitelist.c.id).where(whitelist.c.id == uid[b'vid'][0].decode())
|
||||
async with database.transaction():
|
||||
result = await database.fetch_one(query)
|
||||
result = await database.fetch_one(query)
|
||||
return result is not None
|
||||
|
||||
async def check_blacklist(uid):
|
||||
@@ -129,8 +140,7 @@ async def check_blacklist(uid):
|
||||
query = select(blacklist.c.id).where(
|
||||
(blacklist.c.id == device_id) | (blacklist.c.id == username)
|
||||
)
|
||||
async with database.transaction():
|
||||
result = await database.fetch_one(query)
|
||||
result = await database.fetch_one(query)
|
||||
return result is None
|
||||
|
||||
async def ensure_user_columns():
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ TITLE_LISTS = {
|
||||
def init_templates():
|
||||
global SONG_LIST, AVATAR_LIST, ITEM_LIST, EXP_UNLOCKED_SONGS
|
||||
|
||||
base_path = 'api/config/'
|
||||
base_path = 'api/config/'
|
||||
print("[TEMPLATES] Initializing templates...")
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user