zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    触屏时间控制
    小程序 坐标算距离 (copy)
    微信小程序 对接口常用
    conversion function to_char to_number
    南通
    日期 function
    数字 function
    字符串处理函数
    沪通铁路1
    NVL NVL2 COALESCE NULLIF decode
  • 原文地址:https://www.cnblogs.com/caibh/p/13759656.html
Copyright © 2011-2022 走看看