This repository has been archived by the owner on Jan 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (41 loc) · 1.74 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from flask import Flask, render_template, send_file, redirect
app = Flask(__name__)
# Define the folder where the files are stored
BASE_FOLDER = r"C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\CustomLevels"
TEMP_FOLDER = "temp"
@app.route('/')
def root():
return redirect('/beatsaber/customlevels')
@app.route('/beatsaber/customlevels')
def dashboard():
# Get list of folders in the base folder
folders = os.listdir(BASE_FOLDER)
return render_template('custom_levels.html', folders=folders, length=len(folders))
@app.route('/beatsaber/download/<path:folder_path>')
def download(folder_path):
# Check if the folder exists in the temporary folder
temp_folder = os.path.join(TEMP_FOLDER, folder_path)
zip_file = os.path.join(TEMP_FOLDER, folder_path + '.zip')
if os.path.exists(zip_file):
print(f"Download from cache: {folder_path}")
else:
print(f"Download using new zip: {folder_path}")
# If the zip file doesn't exist in temp, zip the folder
folder_to_zip = os.path.join(BASE_FOLDER, folder_path)
os.makedirs(os.path.dirname(zip_file), exist_ok=True)
# Zip the folder
import zipfile
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(folder_to_zip):
for file in files:
zipf.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file), folder_to_zip))
# Return the zip file
return send_file(zip_file, as_attachment=True)
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=5000,
debug=False
)