Karl 4352004ed3 feat(app): restructure as a modern Flask API
This commit refactors the entire backend application into a more structured and maintainable Flask project. It introduces an application factory pattern, consolidates routes into a blueprint, and implements a robust authentication and database layer.

- Introduces a Flask application factory (`create_app` in `main.py`) for better organization and testability.
- Consolidates all API routes into a single blueprint (`routes/api.py`) for modularity.
- Implements a new basic authentication system using a decorator (`@requires_basic_auth`) to secure all endpoints.
- Refactors the database access layer with standardized query execution and connection handling.
- Adds new modules for core logic, including an account checker (`checker.py`) and user retrieval (`get_users.py`).
- Updates the VSCode launch configuration to support the new Flask application structure.

BREAKING CHANGE: The application has been completely restructured. The old `server.py` entry point is removed. The application should now be run via the app factory in `main.py`. All API endpoints now require basic authentication.
2025-07-13 19:40:04 +01:00

52 lines
1.7 KiB
Python

import os
from dotenv import load_dotenv
import requests
import json
from requests_tor import RequestsTor
load_dotenv()
torpass = os.getenv('TORSPWD')
rt = RequestsTor(tor_ports=(9001, 9002, 9003, 9004, 9005), tor_cport=9051, password=torpass, autochange_id=5)
def get_latest_urls_from_dns():
with open('./ktvmanager/lib/DNS_list.txt') as f:
lines = [line.rstrip('\n') for line in f]
with open('./ktvmanager/lib/extra_urls.txt') as urls:
extra_urls = [line.rstrip('\n') for line in urls]
# print(lines)
complete_list_of_urls = []
for url in lines:
data = requests.get(url)
try:
content = json.loads(data.text)
except Exception:
pass
try:
list_of_urls = content['su'].split(',')
except KeyError:
list_of_urls = content['fu'].split(',')
for url in list_of_urls:
complete_list_of_urls.append(url)
complete_list_of_urls = list(set(complete_list_of_urls))
for url in extra_urls:
complete_list_of_urls.append(url)
return list(dict.fromkeys(complete_list_of_urls))
def generate_urls_for_user(username, password):
new_urls = []
for url in get_latest_urls_from_dns():
hard_url = f'/player_api.php?password={password}&username={username}&action=user&sub=info'
new_url = url + hard_url
new_urls.append(new_url)
return new_urls
def check_for_url_from_details(username, password):
new_urls = []
for url in get_latest_urls_from_dns():
hard_url = f'/player_api.php?password={password}&username={username}&action=user&sub=info'
new_url = url + hard_url
new_urls.append(new_url)
print(new_urls)