pri_config.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. memo() {
  2. # 获取传入的参数
  3. updatedContent=$*
  4. # 转义特殊字符
  5. # escapedContent=$(echo -n "$updatedContent" | jq -sRr @uri)
  6. # 构建请求体数据
  7. # data="{\"content\": \"$escapedContent\"}"
  8. # 构建请求体数据
  9. data="{\"content\": \"$updatedContent\"}"
  10. # 发送请求
  11. response=$(curl -s -X POST -H "Content-Type: application/json" \
  12. -H "Authorization: bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E" \
  13. -d "$data" \
  14. "https://memos.tianyunperfect.cn/api/v1/memo")
  15. # 判断是否存在name字段
  16. if [[ $response == *"name"* ]]; then
  17. echo "记录成功 https://memos.tianyunperfect.cn"
  18. else
  19. echo "失败" $response
  20. fi
  21. }
  22. todo(){
  23. memo "#todo $*"
  24. }
  25. function upload_file() {
  26. file_path=$1
  27. if [ -z "$file_path" ]; then
  28. echo "Error: file_path is empty!"
  29. return 1
  30. fi
  31. if [ ! -f "$file_path" ]; then
  32. echo "Error: file not exist!"
  33. return 1
  34. fi
  35. oss_path=$2
  36. # 如果没有传入oss路径,则
  37. if [ -z "$oss_path" ]; then
  38. oss_path="file"
  39. fi
  40. curl -k -X POST -F "file=@$file_path" -F "oss_path=$oss_path" https://web_history.tianyunperfect.cn/oss/upload_file
  41. file_name=$(basename "$file_path")
  42. echo ''
  43. echo "https://alist.tianyunperfect.cn/oss_gang/$oss_path/$file_name"
  44. echo "https://tianyunperfect.oss-cn-hongkong.aliyuncs.com/$oss_path/$file_name"
  45. }