memo() { # 获取传入的参数 updatedContent=$* # 转义特殊字符 # escapedContent=$(echo -n "$updatedContent" | jq -sRr @uri) # 构建请求体数据 # data="{\"content\": \"$escapedContent\"}" # 构建请求体数据 data="{\"content\": \"$updatedContent\"}" # 发送请求 response=$(curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E" \ -d "$data" \ "https://memos.tianyunperfect.cn/api/v1/memo") # 判断是否存在name字段 if [[ $response == *"name"* ]]; then echo "记录成功 https://memos.tianyunperfect.cn" else echo "失败" $response fi } todo(){ memo "#todo $*" } # 通用上传函数 function upload_file_common() { local file_path="$1" local upload_url="$2" # 检查文件路径是否为空 if [ -z "$file_path" ]; then echo "Error: file_path is empty!" return 1 fi # 检查文件是否存在 if [ ! -f "$file_path" ]; then echo "Error: file does not exist!" return 1 fi # 使用curl上传文件并获取响应 local response=$(curl -k -X POST -F "file=@$file_path" "$upload_url") echo $response # 解析JSON响应,提取path字段 local path=$(echo "$response" | jq -r '.path') if [ -z "$path" ]; then echo "Error: Failed to get the path from the response!" return 1 fi echo '' echo "https://alist.tianyunperfect.cn/oss_jing1/$path" echo "https://kedaoyun.tianyunperfect.cn/#explorer&pathFile=%7Bio:5%7D/$path" echo "https://oss_b_1.tianyunperfect.cn/$path" echo "https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/$path" } # 上传文件到指定的URL function upload_file() { upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_file" } # 上传临时文件到指定的URL function upload_tmp_file() { upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_tmp_file" }