-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
90 lines (68 loc) · 1.8 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask,session,request
from logzero import logger
from flask_cors import CORS
import user
import disk
import json
logger.info("正在开启应用")
app = Flask("file_manage")
app.debug = True
cors = CORS(app, resources={r"*": {
"origins": "*",
"methods": "GET,POST,OPTIONS,PUT,DELETE,PATCH",
"expose_headers": "*",
"allow_headers": "*",
"supports_credentials": "*",
"max_age": "*",
}})
# 返回json
def get_json(obj):
return json.dumps(obj)
# 返回success的info
def return_success_data(data):
return json.dumps({
"success": True,
"data": data
})
# 返回失败的info
def return_failed_data(msg):
return json.dumps({
"success": False,
"message": msg
})
# 返回需要登录的头
def return_unauthorized():
return json.dumps({"needAuth": True})
@app.route('/*',methods=['OPTIONS'])
def fake():
return ""
@app.route('/ls',methods=['GET'])
def list_dirs():
data = request.args.get("path")
path = disk.find_dic_item(data)
res = []
for i in path.dic:
res.append({
"name": i.file_name,
"create_time": i.create_time,
"tag": i.tag
})
return return_success_data(res)
@app.route('/del',methods=['GET'])
def del_file():
data = request.args.get("path")
disk.delete_command(['', data])
return return_success_data("success")
@app.route('/mkdir',methods=['GET'])
def mkdir():
data = request.args.get("path")
disk.mkdir(['', data])
return return_success_data("success")
@app.route('/create',methods=['GET'])
def create():
data = request.args.get("path")
disk.create(['', data])
return return_success_data("success")
if __name__ == "__main__":
logger.info("读取配置文件")
app.run(host='0.0.0.0', threaded=False)