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 path1=$(echo "$response" | jq -r '.path') if [ -z "$path1" ]; then echo "Error: Failed to get the path from the response!" return 1 fi echo '' echo "https://alist.tianyunperfect.cn/oss_jing1/$path1" echo "https://kedaoyun.tianyunperfect.cn/#explorer&pathFile=%7Bio:5%7D/$path1" echo "https://oss_b_1.tianyunperfect.cn/$path1" echo "https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/$path1" } # 上传文件到指定的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" } # 获取本机IP地址 get_ip_address() { 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) echo "$ip_address" } # 设置代理 set_proxy() { local ip=$(get_ip_address) local proxy_command="export https_proxy=http://${ip}:7890 http_proxy=http://${ip}:7890 all_proxy=socks5://${ip}:7890" echo "$proxy_command" eval "$proxy_command" echo "Proxy has been set to $ip:7890" } # 取消代理设置 unset_proxy() { local unset_command="unset https_proxy http_proxy all_proxy" echo "$unset_command" eval "$unset_command" echo "Proxy has been unset" }