pri_config.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 path1=$(echo "$response" | jq -r '.path')
  44. if [ -z "$path1" ]; 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/$path1"
  50. echo "https://kedaoyun.tianyunperfect.cn/#explorer&pathFile=%7Bio:5%7D/$path1"
  51. echo "https://oss_b_1.tianyunperfect.cn/$path1"
  52. echo "https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/$path1"
  53. }
  54. # 上传文件到指定的URL
  55. function upload_file() {
  56. upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_file"
  57. }
  58. # 上传临时文件到指定的URL
  59. function upload_tmp_file() {
  60. upload_file_common "$1" "https://web_history.tianyunperfect.cn/oss/upload_tmp_file"
  61. }
  62. # 获取本机IP地址
  63. get_ip_address() {
  64. ip_address=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1)
  65. echo "$ip_address"
  66. }
  67. # 设置代理
  68. set_proxy() {
  69. local ip=$(get_ip_address)
  70. local proxy_command="export https_proxy=http://${ip}:7890 http_proxy=http://${ip}:7890 all_proxy=socks5://${ip}:7890"
  71. echo "$proxy_command"
  72. eval "$proxy_command"
  73. echo "Proxy has been set to $ip:7890"
  74. }
  75. # 取消代理设置
  76. unset_proxy() {
  77. local unset_command="unset https_proxy http_proxy all_proxy"
  78. echo "$unset_command"
  79. eval "$unset_command"
  80. echo "Proxy has been unset"
  81. }