Adaptions for new server codebase

This commit is contained in:
UnitedAirforce
2025-05-11 20:37:22 +08:00
parent a1e8fd08c8
commit fbb1bf5266
6 changed files with 16 additions and 17 deletions

31
7001.py
View File

@@ -1,5 +1,5 @@
from flask import Flask, request, jsonify, send_file from flask import Flask, request, jsonify, send_file
from config import Config from config_old import Config
import os import os
import sqlite3 import sqlite3
import binascii import binascii
@@ -13,19 +13,19 @@ import json
import requests import requests
try: try:
with open("song_list.json", 'r', encoding="utf-8") as file: with open("api/config/song_list.json", 'r', encoding="utf-8") as file:
song_list = json.load(file) song_list = json.load(file)
except Exception as e: except Exception as e:
print(f"An unexpected error occurred when loading song_list.json: {e}") print(f"An unexpected error occurred when loading song_list.json: {e}")
try: try:
with open("avatar_list.json", 'r', encoding="utf-8") as file: with open("api/config/avatar_list.json", 'r', encoding="utf-8") as file:
avatar_list = json.load(file) avatar_list = json.load(file)
except Exception as e: except Exception as e:
print(f"An unexpected error occurred when loading avatar_list.json: {e}") print(f"An unexpected error occurred when loading avatar_list.json: {e}")
try: try:
with open("item_list.json", 'r', encoding="utf-8") as file: with open("api/config/item_list.json", 'r', encoding="utf-8") as file:
item_list = json.load(file) item_list = json.load(file)
except Exception as e: except Exception as e:
print(f"An unexpected error occurred when loading item_list.json: {e}") print(f"An unexpected error occurred when loading item_list.json: {e}")
@@ -64,7 +64,7 @@ exclude_stage_exp = [121,134,166,167,168,169,170,213,214,215,225,277] # 134 and
exclude_avatar_exp = [28,29] exclude_avatar_exp = [28,29]
try: try:
with open("exp_unlocked_songs.json", 'r', encoding="utf-8") as file: with open("api/config/exp_unlocked_songs.json", 'r', encoding="utf-8") as file:
exp_unlocked_songs = json.load(file) exp_unlocked_songs = json.load(file)
except Exception as e: except Exception as e:
print(f"An unexpected error occurred when loading exp_unlocked_songs.json: {e}") print(f"An unexpected error occurred when loading exp_unlocked_songs.json: {e}")
@@ -330,9 +330,7 @@ def inform_page(text, mode):
with open("files/inform.html", "r") as file: with open("files/inform.html", "r") as file:
return file.read().format(text=text, img=mode) return file.read().format(text=text, img=mode)
#Serving CDN files
root_folder = os.path.dirname(os.path.abspath(__file__)) root_folder = os.path.dirname(os.path.abspath(__file__))
allowed_folders = ["files"]
@app.route('/info.php', methods=['GET']) @app.route('/info.php', methods=['GET'])
def info(): def info():
@@ -579,9 +577,6 @@ def bonus():
daily_reward_elem = root.find(".//login_bonus") daily_reward_elem = root.find(".//login_bonus")
last_count_elem = daily_reward_elem.find("last_count") last_count_elem = daily_reward_elem.find("last_count")
if last_count_elem is None or not last_count_elem.text.isdigit(): if last_count_elem is None or not last_count_elem.text.isdigit():
return jsonify({"error": "Invalid or missing last_count in XML"}), 500 return jsonify({"error": "Invalid or missing last_count in XML"}), 500
last_count = int(last_count_elem.text) last_count = int(last_count_elem.text)
@@ -590,14 +585,14 @@ def bonus():
cursor = connection.cursor() cursor = connection.cursor()
# Check for an existing row # Check for an existing row
cursor.execute("SELECT day, timestamp, my_avatar, my_stage FROM daily_reward WHERE device_id = ?", (device_id,)) cursor.execute("SELECT day, timestamp FROM daily_reward WHERE device_id = ?", (device_id,))
row = cursor.fetchone() row = cursor.fetchone()
time = datetime.now() time = datetime.now()
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S") formatted_time = time.strftime("%Y-%m-%d %H:%M:%S")
if row is not None: if row is not None:
current_day, last_timestamp, my_avatar, my_stage = row current_day, last_timestamp = row
last_date = datetime.strptime(last_timestamp, "%Y-%m-%d %H:%M:%S") last_date = datetime.strptime(last_timestamp, "%Y-%m-%d %H:%M:%S")
# Check if one day has passed # Check if one day has passed
@@ -626,7 +621,7 @@ def bonus():
my_avatar = json.dumps(list(avatars)) my_avatar = json.dumps(list(avatars))
# Update the table # Update the table
cursor.execute("""UPDATE daily_reward SET timestamp = ?, day = ?, my_avatar = ?, my_stage = ? WHERE device_id = ?""", (formatted_time, current_day, my_avatar, my_stage, device_id)) cursor.execute("""UPDATE daily_reward SET timestamp = ?, day = ? WHERE device_id = ?""", (formatted_time, current_day, device_id))
# return 0 obj # return 0 obj
xml_response = "<response><code>0</code></response>" xml_response = "<response><code>0</code></response>"
@@ -1264,7 +1259,7 @@ def ranking_detail():
row_content.append(f"""<div class="bt_bg01_ac">{label}</div>""") row_content.append(f"""<div class="bt_bg01_ac">{label}</div>""")
else: else:
encrypted_mass = encryptAES(("vid=" + device_id + "&song_id=" + str(song_id) + "&mode=" + str(mode_value) + "&dummy=").encode("utf-8")) encrypted_mass = encryptAES(("vid=" + device_id + "&song_id=" + str(song_id) + "&mode=" + str(mode_value) + "&dummy=").encode("utf-8"))
row_content.append(f"""<a href="/ranking_detail.php?{encrypted_mass}" class="bt_bg01">{label}</a>""") row_content.append(f"""<a href="/ranking_detail.php?{encrypted_mass}" class="bt_bg01_xnarrow">{label}</a>""")
if len(row_content) == 3: if len(row_content) == 3:
html += row_start + ''.join(row_content) + row_end html += row_start + ''.join(row_content) + row_end
@@ -1466,7 +1461,7 @@ def ranking_detail():
encrypted_mass = encryptAES(("vid=" + device_id + "&dummy=").encode("utf-8")) encrypted_mass = encryptAES(("vid=" + device_id + "&dummy=").encode("utf-8"))
html += f""" html += f"""
<a href="/ranking.php?{encrypted_mass}" class="bt_bg01_ifedup" style="margin: 20px auto; display: block; text-align: center;"> <a href="/ranking.php?{encrypted_mass}" class="bt_bg01" style="margin: 20px auto; display: block; text-align: center;">
Go Back Go Back
</a> </a>
""" """
@@ -1541,7 +1536,7 @@ def status():
else: else:
encrypted_mass = encryptAES(f"vid={device_id}&page_id={i}&dummy=".encode("utf-8")) encrypted_mass = encryptAES(f"vid={device_id}&page_id={i}&dummy=".encode("utf-8"))
buttons_html += f""" buttons_html += f"""
<a href="/status.php?{encrypted_mass}" class="bt_bg01" > <a href="/status.php?{encrypted_mass}" class="bt_bg01_xnarrow" >
{page_name[i]} {page_name[i]}
</a> </a>
""" """
@@ -1821,6 +1816,10 @@ def delete_account():
# this only tricks the client to clear its local data for now # this only tricks the client to clear its local data for now
return """<?xml version="1.0" encoding="UTF-8"?><response><code>0</code><taito_id></taito_id></response>""" return """<?xml version="1.0" encoding="UTF-8"?><response><code>0</code><taito_id></taito_id></response>"""
#Serving CDN files
root_folder = os.path.dirname(os.path.abspath(__file__))
allowed_folders = ["files"]
@app.route('/<path:path>', methods=['GET']) @app.route('/<path:path>', methods=['GET'])
def get_file(path): def get_file(path):
file_path = os.path.join(root_folder, path) file_path = os.path.join(root_folder, path)