You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9 KiB

from sanic import Blueprint, Request, Sanic
from ..common import common_api
bp_sif_download = Blueprint("sif_download", url_prefix="download")
@bp_sif_download.route("additional", methods=["POST"])
@common_api
async def additional(request: Request):
request_data = request.ctx.request_data
static_root = Sanic.get_app().config["STATIC_ROOT"]
package_type = request_data.get("package_type", 0)
package_id = request_data.get("package_id", 0)
target_os = request_data.get("target_os", "")
download_resp = []
package_list = Sanic.get_app().ctx.assets_list[target_os][package_type][package_id]
static_root = Sanic.get_app().config["STATIC_ROOT"]
for package_order, package_size in package_list:
download_resp.append({
"size": package_size,
"url": f"{static_root}/{target_os}/{package_type}_{package_id}_{package_order}.zip"
})
return download_resp
@bp_sif_download.route("batch", methods=["POST"])
@common_api
async def batch(request: Request):
request_data = request.ctx.request_data
static_root = Sanic.get_app().config["STATIC_ROOT"]
resp = []
if request_data.get("client_version", "") == Sanic.get_app().config["PACKAGE_VERSION"]: # 97.4.6
package_type = request_data.get("package_type", 0)
excluded_package_ids = request_data.get("excluded_package_ids", [])
os = request_data.get("os", "")
package_dict = Sanic.get_app().ctx.assets_list[os][package_type]
for package_id, package_order_list in package_dict.items():
if package_id in excluded_package_ids: continue
package_order_list.sort(key=lambda x: x[0])
for package_order, package_size in package_order_list:
resp.append({
"size": package_size,
"url": f"{static_root}/{os}/{package_type}_{package_id}_{package_order}.zip"
})
return resp
@bp_sif_download.route("update", methods=["POST"])
@common_api
async def update(request: Request):
request_data = request.ctx.request_data
static_root = Sanic.get_app().config["STATIC_ROOT"]
version = Sanic.get_app().config["PACKAGE_VERSION"]
target_os = request_data.get("target_os", "")
resp = []
if request_data.get("external_version", "") != version: # 97.4.6
package_type = 99
package_dict = Sanic.get_app().ctx.assets_list[target_os][package_type]
for package_id, package_order_list in package_dict.items():
package_order_list.sort(key=lambda x: x[0])
for package_order, package_size in package_order_list:
resp.append({
"size": package_size,
"url": f"{static_root}/{target_os}/{package_type}_{package_id}_{package_order}.zip",
"version": version
})
return resp
@bp_sif_download.route("event", methods=["POST"])
@common_api
async def event(request: Request):
return []