shell脚本+gitee实现Typora自定义图床
imgitee.sh
#!/bin/bash
token="xxxxx"
owner="ccccccc"
repo="ccccc"
today="`date +%Y-%m-%d`"
message="imgitee upload"
# 逐个上传图片到gitee
for i in "$@"; do
# 文件取md5
md5=$(md5sum $i | cut -d ' ' -f 1)
# 取文件名
fname=${i##*/}
# git仓库存放路径 = 日期/md5-文件名
path=$today/$md5-$fname
# 文件内容转base64
content=$(base64 -w 0 $i)
# 调gitee接口上传
url="https://gitee.com/api/v5/repos/${owner}/$repo/contents/$path"
curl -X POST --header 'Content-Type: application/json;charset=UTF-8' "$url" -d "{\"access_token\":\"$token\",\"content\":\"$content\",\"message\":\"$message\"}"
done
# 输出结果给Typora
echo "Upload Success:"
for i in "$@"; do
# 文件取md5
md5=$(md5sum $i | cut -d ' ' -f 1)
# 取文件名
fname=${i##*/}
# git仓库存放路径 = 日期/md5-文件名
path=$today/$md5-$fname
# 刚才上传返回的download_url就是这个格式
url="https://gitee.com/$owner/$repo/raw/master/$path"
echo $url
done