Typora+Lsky Pro实现优雅的写博客
众所周知啊,我还挺喜欢用Typora写东西的,然后嘞,其实也不怎么需要图床。
不过啊,为了看上去高端一点,所以也跟风用用图床。
不知道什么原因啊,PicGo的方案老是抽风,总是失败啊,所以配合这个自定义命令,做为新的方案使用
import sys
import requests
import os
# 配置信息(根据你的图床修改)
CONFIG = {
"api_url": "https://your-lsky-domain.com/api/v1/upload",
"token": "your-api-token-here", # Bearer Token
"album_id": None, # 可选相册ID
"strategy": "default" # 存储策略
}
def upload_image(image_path):
headers = {
"Authorization": f"Bearer {CONFIG['token']}"
}
files = {
'file': (os.path.basename(image_path),
open(image_path, 'rb').read()
}
data = {
"album_id": CONFIG['album_id'],
"strategy": CONFIG['strategy']
}
try:
response = requests.post(
CONFIG['api_url'],
headers=headers,
files=files,
data=data
)
result = response.json()
if response.status_code == 200 and result.get("status"):
return result["data"]["links"]["url"]
else:
return f"Error: {result.get('message', 'Unknown error')}"
except Exception as e:
return f"Exception: {str(e)}"
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python lskypro_uploader.py <image_path>")
sys.exit(1)
image_path = sys.argv[1]
result = upload_image(image_path)
print(result)