|
import os
|
|
import shutil
|
|
from flask import Flask, send_from_directory, abort, render_template_string
|
|
import subprocess
|
|
|
|
|
|
temp_dir = "./"
|
|
|
|
|
|
def clone_and_setup_repo():
|
|
|
|
os.system("npm i")
|
|
|
|
|
|
print("Patching server.ts for iframe embedding...")
|
|
os.system(r"""sed -i.bak '/fastifyHelmet/s/});/ frameguard: false\\n});/' server/server.ts""")
|
|
|
|
os.system("cp config.example.toml config.toml")
|
|
os.system("npm run build")
|
|
os.system("npm start")
|
|
|
|
|
|
index_html_path = os.path.join(temp_dir, 'index.html')
|
|
if os.path.exists(index_html_path):
|
|
if os.path.exists('index.html'):
|
|
os.remove('index.html')
|
|
shutil.move(index_html_path, '.')
|
|
|
|
|
|
if not os.path.exists('static'):
|
|
os.mkdir('static')
|
|
for item in os.listdir(temp_dir):
|
|
if item != 'index.html':
|
|
shutil.move(os.path.join(temp_dir, item), os.path.join('static', item))
|
|
|
|
|
|
clone_and_setup_repo()
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route('/')
|
|
def index():
|
|
|
|
if not os.path.exists("index.html"):
|
|
return abort(404, description="index.html not found.")
|
|
|
|
|
|
with open("index.html", "r") as file:
|
|
index_html_content = file.read()
|
|
|
|
return render_template_string(index_html_content)
|
|
|
|
|
|
@app.route('/<path:filename>')
|
|
def static_files(filename):
|
|
return send_from_directory('static', filename)
|
|
|
|
|
|
@app.route('/check_main_js')
|
|
def check_main_js():
|
|
if os.path.exists('static/main.js'):
|
|
return "main.js exists."
|
|
else:
|
|
return "main.js does not exist."
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', port=7860)
|
|
|