From 2e771f765202dc449fce2e6471a889f4318fcff0 Mon Sep 17 00:00:00 2001 From: shuoGG1239 <328893769@qq.com> Date: Fri, 10 Jan 2020 19:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=88=90v2=E7=9A=84smms?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- UploadWidget.py | 7 ++++--- config.json | 3 +++ util/sm_util.py | 11 ++++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 config.json diff --git a/README.md b/README.md index 97030ef..9511424 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ * PyQt5 * pywin32 - +## 配置 +* 根目录的`config.json`里面的`SecretToken`填自己的sm.ms的Token, 懒得申请可以我的自己的(默认)... ## 效果 diff --git a/UploadWidget.py b/UploadWidget.py index f66e735..971a40c 100644 --- a/UploadWidget.py +++ b/UploadWidget.py @@ -120,9 +120,10 @@ def __slot_sm_response(self, resp_json): self.loadingLabel.hide() if resp_json is not '': ret = json.loads(resp_json) - md_image = '![' + ret['filename'] + '](' + ret['url'] + ')' - self.ui.lineEdit.setText(md_image) - system_util.set_clipboard_text(md_image) + if ret['success'] is True: + md_image = '![' + ret['filename'] + '](' + ret['url'] + ')' + self.ui.lineEdit.setText(md_image) + system_util.set_clipboard_text(md_image) def __init_loading_gif(self): """ diff --git a/config.json b/config.json new file mode 100644 index 0000000..7f1ccef --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "SecretToken":"lELFWItOQDNxnTuzmGn4NUMictfhITfn" +} \ No newline at end of file diff --git a/util/sm_util.py b/util/sm_util.py index 8dad89a..8158f56 100644 --- a/util/sm_util.py +++ b/util/sm_util.py @@ -4,16 +4,21 @@ import requests +conf_json = json.load(open("config.json")) def upload_img(image_path): + if conf_json is None: + raise Exception("conf_json is None") files_map = [('smfile', image_path)] file_name = os.path.split(image_path)[1] params = { - 'ssl': False, - 'format': 'png' + 'format': 'json' } multi_files = list(map(lambda x: (x[0], (urllib.parse.quote(os.path.split(x[1])[1]), open(x[1], 'rb'))), files_map)) - resp = requests.post("https://sm.ms/api/upload", data=params, files=multi_files) + header = { + "Authorization": conf_json["SecretToken"] + } + resp = requests.post("https://sm.ms/api/v2/upload", data=params, files=multi_files, headers=header) print(resp.text) result = json.loads(resp.text) if result['code'] == 'success':