pri_config.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. # 通用上传函数
  26. function upload_file_common() {
  27. local file_path="$1"
  28. local upload_url="$2"
  29. # 检查文件路径是否为空
  30. if [ -z "$file_path" ]; then
  31. echo "Error: file_path is empty!"
  32. return 1
  33. fi
  34. # 检查文件是否存在
  35. if [ ! -f "$file_path" ]; then
  36. echo "Error: file does not exist!"
  37. return 1
  38. fi
  39. # 使用curl上传文件并获取响应
  40. local response=$(curl -k -X POST -F "file=@$file_path" "$upload_url")
  41. echo $response
  42. # 解析JSON响应,提取path字段
  43. local path=$(echo "$response" | jq -r '.path')
  44. if [ -z "$path" ]; then
  45. echo "Error: Failed to get the path from the response!"
  46. return 1
  47. fi
  48. echo ''
  49. echo "https://alist.tianyunperfect.cn/oss_jing1/$path"
  50. echo "https://oss_b_1.tianyunperfect.cn/$path"
  51. echo "https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/$path"
  52. }
  53. # 上传文件到指定的URL
  54. function upload_file() {
  55. upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_file"
  56. }
  57. # 上传临时文件到指定的URL
  58. function upload_tmp_file() {
  59. upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_tmp_file"
  60. }