CrimsonSorcerer commited on
Commit
ad4b5e2
·
verified ·
1 Parent(s): cc66467

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, send_file, jsonify
2
+ import subprocess, os, shutil, uuid, tempfile
3
+
4
+ app = Flask(__name__)
5
+
6
+ BUILD_SCRIPT = "/app/build_apk.sh"
7
+ KEYSTORE = "/opt/debug.keystore"
8
+
9
+ @app.route("/")
10
+ def index():
11
+ return jsonify({"status": "HtStudio APK Builder çalışıyor 🚀"})
12
+
13
+ @app.route("/build", methods=["POST"])
14
+ def build():
15
+ data = request.get_json(force=True)
16
+ html_code = data.get("html", "")
17
+ app_name = data.get("name", "HtApp").strip().replace(" ", "_")
18
+ pkg_name = data.get("pkg", "com.htstudio.app").strip()
19
+
20
+ if not html_code.strip():
21
+ return jsonify({"error": "HTML boş"}), 400
22
+
23
+ # Geçici klasör
24
+ job_id = str(uuid.uuid4())[:8]
25
+ work_dir = f"/tmp/build_{job_id}"
26
+ os.makedirs(work_dir, exist_ok=True)
27
+
28
+ try:
29
+ # HTML dosyasını yaz
30
+ with open(f"{work_dir}/index.html", "w", encoding="utf-8") as f:
31
+ f.write(html_code)
32
+
33
+ # Build script'i çalıştır
34
+ result = subprocess.run(
35
+ ["bash", BUILD_SCRIPT, work_dir, app_name, pkg_name, KEYSTORE],
36
+ capture_output=True, text=True, timeout=120
37
+ )
38
+
39
+ if result.returncode != 0:
40
+ return jsonify({
41
+ "error": "Derleme başarısız",
42
+ "log": result.stderr[-2000:]
43
+ }), 500
44
+
45
+ apk_path = f"{work_dir}/output.apk"
46
+ if not os.path.exists(apk_path):
47
+ return jsonify({"error": "APK oluşturulamadı"}), 500
48
+
49
+ return send_file(
50
+ apk_path,
51
+ as_attachment=True,
52
+ download_name=f"{app_name}_HtStudio.apk",
53
+ mimetype="application/vnd.android.package-archive"
54
+ )
55
+
56
+ finally:
57
+ shutil.rmtree(work_dir, ignore_errors=True)
58
+
59
+ if __name__ == "__main__":
60
+ app.run(host="0.0.0.0", port=7860)
61
+