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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
'''
Author: your name
Date: 2021-07-09 12:39:40
LastEditTime: 2021-07-19 13:58:36
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\views\file.py
'''
import traceback
from pathlib import Path
from flask import current_app, jsonify, request, make_response, Response
from flask_restful import Resource, fields
from marshmallow import Schema, fields
from werkzeug.datastructures import FileStorage
from flask_restful.reqparse import RequestParser
from flask_jwt_extended import ( jwt_required, get_jwt_identity )
from application.signal_manager import signalManager
from webcreator.log import logger
from webcreator.response import ResponseCode, response_result
class FileInit(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
@jwt_required(locations=["headers"])
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("path", type=str, location="args", required=False)
args = self.parser.parse_args()
try:
jwt = get_jwt_identity()
result, message = signalManager.actionGetFileInit.emit(args.path, jwt)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileContent(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
@jwt_required(locations=["headers"])
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="args", required=True)
self.parser.add_argument("path", type=str, location="args", required=False, default=None)
self.parser.add_argument("root", type=str, location="args", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionGetFileContent.emit(args.disk, args.path, args.root)
if result:
response = { 'result': { 'message': None, 'status': "success" } }
response.update(result)
return response
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileTree(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
@jwt_required(locations=["headers"])
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="args", required=True)
self.parser.add_argument("path", type=str, location="args", required=False)
self.parser.add_argument("root", type=str, location="args", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionGetFileTree.emit(args.disk, args.path, args.root)
if result:
response = { 'result': { 'message': None, 'status': "success" }, 'directories': None }
response.update({ 'directories': result })
return response
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileDisk(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="args", required=True)
self.parser.add_argument("path", type=str, location="args", required=False)
args = self.parser.parse_args()
try:
result, message = signalManager.actionGetFileDisk.emit(args.disk)
if result:
return { 'information': list(message), 'result': { 'message': "Disk selected!", 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileUpdate(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
# logger.info(request.form)
self.parser.add_argument("disk", type=str, location="form", required=True)
self.parser.add_argument("path", type=str, location="form", nullable=False, required=True)
self.parser.add_argument("file", type=FileStorage, location="files", required=True)
args = self.parser.parse_args()
try:
# logger.info(args.path)
file = request.files.get("file") # args.get('file')
result, message = signalManager.actionPostFileUpdate.emit(args.disk, args.path, file)
if result:
return { 'config': result, 'result': { 'message': "file update success", 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileUpload(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
self.parser.add_argument("disk", type=str, location="form", required=True)
self.parser.add_argument("path", type=str, location="form", required=True)
self.parser.add_argument("overwrite", type=int, location="form", default=0, required=True)
self.parser.add_argument("files", type=FileStorage, location="files", required=True, action='append')
args = self.parser.parse_args()
try:
fileList = request.files.getlist('files')
result, message = signalManager.actionPostFileUpload.emit(args.disk, args.path, args.overwrite, fileList)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileDelete(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="json", required=True)
# self.parser.add_argument("items", type=fields.Raw, location="json", required=True) # items: [{path: "code/app.php", type: "file"}]
args = self.parser.parse_args()
try:
json_payload = request.json
logger.info(json_payload)
if not json_payload:
return False, ResponseCode.HTTP_INVAILD_REQUEST
result, message = signalManager.actionPostFileDelete.emit(**json_payload)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileCreate(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="json", required=True)
self.parser.add_argument("path", type=str, location="json", required=True)
self.parser.add_argument("name", type=str, location="json", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionPostFileCreate.emit(args.disk, args.path, args.name)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileCreateDir(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="json", required=True)
self.parser.add_argument("path", type=str, location="json", required=True)
self.parser.add_argument("name", type=str, location="json", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionPostFileCreateDir.emit(args.disk, args.path, args.name)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FilePaste(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def post(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="json", required=True)
self.parser.add_argument("clipboard", type=dict, location="json", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionPostFilePaste.emit(args.disk, args.items)
if result:
return { 'config': result, 'result': { 'message': None, 'status': "success" } }
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FileDownload(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="args", required=True)
self.parser.add_argument("path", type=str, location="args", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionGetFileDown.emit(args.disk, args.path)
if result:
resp, mime = result
# return Response(resp, mimetype='text/xml')
return Response(resp, content_type='{}; charset=utf-8'.format(mime))
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
class FilePrview(Resource):
def __init__(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser = RequestParser()
@jwt_required(locations=["headers"])
def get(self):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self.parser.add_argument("disk", type=str, location="args", required=True)
self.parser.add_argument("path", type=str, location="args", required=True)
args = self.parser.parse_args()
try:
result, message = signalManager.actionGetFilePreview.emit(args.disk, args.path)
if result:
content, mime = result
resp = make_response(content)
resp.mimetype = mime
return resp
return { 'information': list(message), 'result': { 'message': "no data", 'status': "fail" } }
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)