@@ -174,7 +174,7 @@ def _delete(directory: str, file: str) -> tuple[Response, int]:
174174
175175 @main_route .route ('/list' , methods = ['GET' ])
176176 @main_route .route ('/list/<directory>' , methods = ['GET' ])
177- def _list (directory : str = "/ " ) -> tuple [Response , int ]:
177+ def _list (directory : str = "" ) -> tuple [Response , int ]:
178178 """
179179 列出指定目录下所有目录
180180
@@ -282,7 +282,7 @@ def _retrieve(directory: str, file: str) -> tuple[Response, int]:
282282
283283 @main_route .route ('/backup' , methods = ['GET' ])
284284 @main_route .route ('/backup/<directory>' , methods = ['GET' ])
285- def _backup (directory : str = '/ ' ) -> tuple [Response , int ]:
285+ def _backup (directory : str = '' ) -> tuple [Response , int ]:
286286 """
287287 创建一个备份任务,具体方式在配置文件中指定
288288
@@ -291,18 +291,29 @@ def _backup(directory: str = '/') -> tuple[Response, int]:
291291 """
292292 info_head = f"{ request .remote_addr } { request .method } { request .path } "
293293
294- bak_name = generate_file_name (cfg ['storage' ]['path' ], '.tar.gz' )
295- bak_path = Path (cfg ['storage' ]['path' ]) / (bak_name + '.tar.gz' )
296- bak_url = join_url (cfg ['network' ]['base_url' ], bak_name + '.tar.gz' )
294+ if not authenticate (cfg ):
295+ lg .warn (f"{ info_head } 401: 认证失败" )
296+ return jsonify ({
297+ "success" : False ,
298+ "message" : "认证失败"
299+ }), 401
300+
301+ bak_name = generate_file_name (Path (cfg ['storage' ]['path' ]), '.tar.gz' )
302+ bak_path = Path (cfg ['storage' ]['path' ]) / bak_name
303+ bak_url = join_url (
304+ cfg ['network' ]['base_url' ] if 'network' in cfg ['network' ] else '' ,
305+ bak_name + '.tar.gz' )
297306
298307 path = Path (cfg ['storage' ]['path' ]) / directory
299308
300309 # 创建新进程压缩备份
301310 # FIXME: 由于是多进程的,这个任务失败了也不会有表示
311+ # FIXME: 备份会包括所有之前所有的 .tar.gz
302312 p = Process (target = backup_to_file , args = (path , bak_path ))
303313 p .start ()
304314
305315 lg .info (f"{ info_head } 200 备份任务创建成功" )
316+ lg .info (f"位置:{ bak_path } .tar.gz" )
306317 return jsonify ({
307318 "success" : True ,
308319 "url" : bak_url ,
0 commit comments