microbamboo commited on
Commit
c108b31
·
1 Parent(s): 118d056

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import hashlib
3
+ from flask import Flask, request, send_file
4
+
5
+ data_folder = 'static'
6
+ os.makedirs(data_folder, exist_ok=True)
7
+
8
+ def get_key_sha256(key):
9
+ sha256 = hashlib.sha256()
10
+ sha256.update(key.encode('utf-8'))
11
+ return sha256.hexdigest()
12
+
13
+ match_sha256 = 'ffa007286cff75ab9c14e42282edd8e7e28b467a6e1bcd3d9b90dc40d375cae3'
14
+
15
+
16
+ app = Flask(__name__)
17
+
18
+ @app.route("/put", methods = ['POST'])
19
+ def put():
20
+ d = request.headers
21
+ key = d['Key']
22
+ if not get_key_sha256(key) == match_sha256:
23
+ return 'err'
24
+ file_name = d['File']
25
+ file = os.path.join(data_folder, file_name)
26
+ folder = os.path.split(file)[0]
27
+ os.makedirs(folder, exist_ok=True)
28
+ print(request.files)
29
+ f = request.files['file']
30
+ f.save(file)
31
+ return "ok"
32
+
33
+ @app.route("/get", methods = ['GET'])
34
+ def get():
35
+ d = request.headers
36
+ key = d['Key']
37
+ if not get_key_sha256(key) == match_sha256:
38
+ return 'err'
39
+ file_name = d['File']
40
+ f = os.path.join(data_folder, file_name)
41
+ return send_file(f)
42
+
43
+ @app.route("/c")
44
+ def c():
45
+ import shutil
46
+ shutil.rmtree(data_folder)
47
+ os.makedirs(data_folder)
48
+ return "ok"
49
+
50
+ if __name__ == "__main__":
51
+ app.run(host="0.0.0.0", port=7860, debug=True)