microbamboo commited on
Commit
7642f6a
·
1 Parent(s): 7849b0f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import uuid
3
+ import shutil
4
+ import hashlib
5
+ import datetime
6
+ from flask import Flask, request
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
+ data_folder = 'static'
16
+ if not os.path.isdir(data_folder):
17
+ os.makedirs(data_folder)
18
+
19
+ app = Flask(__name__, static_url_path='')
20
+ @app.route("/put", methods = ['POST'])
21
+ def put():
22
+ d = request.json
23
+ key = d['key']
24
+ if not get_key_sha256(key) == match_sha256:
25
+ return 'err'
26
+ msg = d['msg']
27
+ now = str(datetime.datetime.now()).replace(':', '_')
28
+ file_name = now + '___'+str(uuid.uuid4())
29
+ open(os.path.join(data_folder, file_name), 'w').write(msg)
30
+ return 'ok'
31
+
32
+ @app.route("/get", methods = ['GET'])
33
+ def get():
34
+ d = request.headers
35
+ key = d['Key']
36
+ if not get_key_sha256(key) == match_sha256:
37
+ return 'err'
38
+ files = sorted(os.listdir(data_folder))
39
+ txt = ''
40
+ for f in files:
41
+ ff = f.split('___')[0]
42
+ ff = ff.replace('_', ':')
43
+ txt += ff+':'
44
+ txt += open(os.path.join(data_folder, f)).read()+'\n'
45
+ return txt
46
+
47
+ @app.route("/clear", methods = ['GET'])
48
+ def clear():
49
+ d = request.headers
50
+ key = d['Key']
51
+ if not get_key_sha256(key) == match_sha256:
52
+ return 'err'
53
+ shutil.rmtree(data_folder)
54
+ os.makedirs(data_folder)
55
+ return 'ok'
56
+
57
+ if __name__ == "__main__":
58
+ app.run(host="0.0.0.0", port=7860, debug=True)