MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / upload_file

Method upload_file

mod/project/node/nodeutil/base.py:434–455  ·  view source on GitHub ↗
(self, filename: str, target_path: str, mode: str = "cover",
                    call_log: Callable[[int, str], None] = None)

Source from the content-addressed store, hash-verified

432
433 # mode -> cover: 覆盖,ignore: 跳过,rename:重命名
434 def upload_file(self, filename: str, target_path: str, mode: str = "cover",
435 call_log: Callable[[int, str], None] = None) -> str:
436 if not os.path.isfile(filename):
437 return "文件:{}不存在".format(filename)
438
439 target_file = os.path.join(target_path, os.path.basename(filename))
440 exits, err = self.target_file_exits(target_file)
441 if err:
442 return err
443 if exits and mode == "ignore":
444 call_log(0, "文件上传:{} -> {},目标文件已存在,跳过上传".format(filename, target_file))
445 return ""
446 if exits and mode == "rename":
447 upload_name = "{}_{}".format(os.path.basename(filename), public.md5(filename))
448 call_log(0, "文件上传:{} -> {},目标文件已存在,将重命名为{}".format(filename, target_file, upload_name))
449 else:
450 upload_name = os.path.basename(filename)
451
452 if os.path.getsize(filename) > 1024 * 1024 * 5:
453 return self._upload_big_file(filename, target_path, upload_name, call_log)
454 else:
455 return self._upload_little_file(filename, target_path, upload_name, call_log)
456
457 def target_file_exits(self, target_file: str) -> Tuple[bool, str]:
458 data, err = self._request("/files", "upload_files_exists", pdata={

Callers

nothing calls this directly

Calls 7

target_file_exitsMethod · 0.95
_upload_big_fileMethod · 0.95
_upload_little_fileMethod · 0.95
basenameMethod · 0.80
formatMethod · 0.45
joinMethod · 0.45
md5Method · 0.45

Tested by

no test coverage detected