diff --git a/main.py b/main.py
index f994ffc..389cbca 100644
--- a/main.py
+++ b/main.py
@@ -5,12 +5,13 @@ import aiosqlite
from quart import Quart, render_template, request, send_from_directory, Response
from datetime import datetime
from babel.dates import format_datetime
-import locale
-locale.setlocale(locale.LC_TIME, 'ru_RU.UTF-8')
+
+
app = Quart(__name__, template_folder='frontend', static_folder='frontend')
DB_PATH = 'maps.db'
+DATA = "/data"
GAME_MODES = {
"Classic": "Классический",
@@ -45,32 +46,33 @@ async def get_maps(page=1, per_page=30):
return maps
def get_image_path(filepath):
- image_path = os.path.join('J:/public/complete/workshop', filepath)
+ image_path = os.path.join(DATA, filepath)
if not os.path.exists(image_path):
- return "http://127.0.0.1:5000/images/image.jpg"
- return f"http://127.0.0.1:5000/images/{filepath.split('/')[0]}/{filepath.split('/')[1]}/{filepath.split('/')[1]}.jpg"
+ return "/images/image.jpg"
+ return f"/images/{filepath.split('/')[0]}/{filepath.split('/')[1]}/{filepath.split('/')[1]}.jpg"
def get_star_image(stars):
if stars is None or stars == 0:
- return "http://127.0.0.1:5000/stars/0-star.png"
- return f"http://127.0.0.1:5000/stars/{stars}-star.png"
+ return "/stars/0-star.png"
+ return f"/stars/{stars}-star.png"
@app.route('/images/
')
async def serve_image(filename):
- image_path = os.path.join('J:/public/complete/workshop', filename)
+ image_path = os.path.join(DATA, filename)
if os.path.exists(image_path):
- return await send_from_directory('J:/public/complete/workshop', filename)
+ return await send_from_directory(DATA, filename)
else:
- default_image_path = os.path.join('J:/public/complete/workshop', 'image.jpg')
+ default_image_path = os.path.join(DATA, 'image.jpg')
if os.path.exists(default_image_path):
- return await send_from_directory('J:/public/complete/workshop', 'image.jpg')
+ return await send_from_directory(DATA, 'image.jpg')
return "Default image not found", 404
@app.route('/stars/')
async def serve_star_image(filename):
- star_path = os.path.join('J:/public/complete/workshop/stars', filename)
+ stars = os.path.join(DATA, 'stars')
+ star_path = os.path.join(stars, filename)
if os.path.exists(star_path):
- return await send_from_directory('J:/public/complete/workshop/stars', filename)
+ return await send_from_directory(stars, filename)
else:
return "Star image not found", 404
@@ -91,10 +93,10 @@ async def download_bsp():
if not image_path:
return "No image path provided", 400
- image_folder = os.path.dirname(image_path.replace("http://127.0.0.1:5000/images/", ""))
+ image_folder = os.path.dirname(image_path.replace("/images/", ""))
bsp_filename = None
- for file in os.listdir(os.path.join('J:/public/complete/workshop', image_folder)):
+ for file in os.listdir(os.path.join(DATA, image_folder)):
if file.endswith('.bsp'):
bsp_filename = file
break
@@ -102,7 +104,7 @@ async def download_bsp():
if not bsp_filename:
return "No .bsp file found in the same directory", 404
- file_path = os.path.join('J:/public/complete/workshop', image_folder, bsp_filename)
+ file_path = os.path.join(DATA, image_folder, bsp_filename)
SPEED_LIMIT = 40 * 1024 * 1024 // 8
@@ -159,7 +161,7 @@ async def main_page():
tags = 'Не найдено'
if file_path:
- file_size = os.path.getsize(os.path.join('J:/public/complete/workshop', file_path))
+ file_size = os.path.getsize(os.path.join(DATA, file_path))
file_size_mb = file_size / (1024 * 1024)
file_size_display = f"{file_size_mb:.2f} MB"
else:
@@ -282,4 +284,8 @@ async def get_maps_filtered(page=1, selected_game_modes=None, start_date=None, e
return maps
if __name__ == '__main__':
- app.run(host='127.0.0.1', port=5000)
+ import hypercorn.asyncio
+ from hypercorn.config import Config
+ config = Config()
+ config.bind = ["0.0.0.0:5000"]
+ hypercorn.asyncio.run(app, config)
diff --git a/maps.db-shm b/maps.db-shm
deleted file mode 100644
index fe9ac28..0000000
Binary files a/maps.db-shm and /dev/null differ
diff --git a/maps.db-wal b/maps.db-wal
deleted file mode 100644
index e69de29..0000000
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..fb00db7
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,4 @@
+aiosqlite~=0.20.0
+Hypercorn~=0.17.3
+Quart~=0.19.6
+babel~=2.16.0
\ No newline at end of file