Skip to content

Commit

Permalink
更新成v2的smms接口
Browse files Browse the repository at this point in the history
  • Loading branch information
shuoGG1239 committed Jan 10, 2020
1 parent 0f3e1d0 commit 2e771f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* PyQt5
* pywin32


## 配置
* 根目录的`config.json`里面的`SecretToken`填自己的sm.ms的Token, 懒得申请可以我的自己的(默认)...

## 效果

Expand Down
7 changes: 4 additions & 3 deletions UploadWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"SecretToken":"lELFWItOQDNxnTuzmGn4NUMictfhITfn"
}
11 changes: 8 additions & 3 deletions util/sm_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 2e771f7

Please sign in to comment.