vortexa64 commited on
Commit
8f2baa3
·
verified ·
1 Parent(s): 76caed0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Directory for user files
7
+ BASE_DIR = "/tmp/userfiles"
8
+ os.makedirs(BASE_DIR, exist_ok=True)
9
+
10
+ @app.route("/")
11
+ def index():
12
+ return render_template("index.html")
13
+
14
+ @app.route("/file-manager", methods=["GET", "POST", "DELETE"])
15
+ def file_manager():
16
+ if request.method == "GET":
17
+ file_list = []
18
+ for root, dirs, files in os.walk(BASE_DIR):
19
+ for name in files:
20
+ full_path = os.path.join(root, name)
21
+ rel_path = os.path.relpath(full_path, BASE_DIR)
22
+ file_list.append(rel_path)
23
+ return jsonify(files=file_list)
24
+
25
+ elif request.method == "POST":
26
+ file = request.files["file"]
27
+ filename = file.filename
28
+ save_path = os.path.join(BASE_DIR, filename)
29
+ file.save(save_path)
30
+ return jsonify(status="success", path=filename)
31
+
32
+ elif request.method == "DELETE":
33
+ filepath = request.json.get("path")
34
+ abs_path = os.path.join(BASE_DIR, filepath)
35
+ if os.path.exists(abs_path):
36
+ os.remove(abs_path)
37
+ return jsonify(status="deleted")
38
+ return jsonify(status="not found")
39
+
40
+ @app.route("/console", methods=["POST"])
41
+ def console():
42
+ code = request.json.get("code")
43
+ try:
44
+ exec_globals = {}
45
+ exec(code, exec_globals)
46
+ return jsonify(output="Berhasil jalanin.")
47
+ except Exception as e:
48
+ return jsonify(output=str(e))
49
+
50
+ if __name__ == "__main__":
51
+ app.run(host="0.0.0.0", port=7860)