def upload_file(self, files, name=""): if not (files and os.path.isfile(files)): return files if not name: name = os.path.basename(files) LOGGER.info(f"Try to upload file {name}") _url = f"{self.kbserver}/file/upload" with open(files, "rb") as fin: files = {"file": fin} outurl = http_request(url=_url, method="POST", files=files) if FileOps.is_remote(outurl): return outurl outurl = outurl.lstrip("/") FileOps.delete(files) return f"{self.kbserver}/{outurl}"
def update_task_status(self, tasks: str, new_status=1): data = { "tasks": tasks, "status": int(new_status) } _url = f"{self.kbserver}/update/status" try: outurl = http_request(url=_url, method="POST", json=data) except Exception as err: LOGGER.error(f"Update kb error: {err}") outurl = None if not outurl: return None if not FileOps.is_remote(outurl): outurl = outurl.lstrip("/") outurl = f"{self.kbserver}/{outurl}" return outurl
def update_db(self, task_info_file): _url = f"{self.kbserver}/update" try: with open(task_info_file, "rb") as fin: files = {"task": fin} outurl = http_request(url=_url, method="POST", files=files) except Exception as err: LOGGER.error(f"Update kb error: {err}") outurl = None else: if not FileOps.is_remote(outurl): outurl = outurl.lstrip("/") outurl = f"{self.kbserver}/{outurl}" FileOps.delete(task_info_file) return outurl