|
@@ -27,25 +27,49 @@ todo(){
|
|
|
}
|
|
|
|
|
|
|
|
|
-function upload_file() {
|
|
|
- file_path=$1
|
|
|
+
|
|
|
+# 通用上传函数
|
|
|
+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 not exist!"
|
|
|
+ echo "Error: file does not exist!"
|
|
|
return 1
|
|
|
fi
|
|
|
- oss_path=$2
|
|
|
- # 如果没有传入oss路径,则
|
|
|
- if [ -z "$oss_path" ]; then
|
|
|
- oss_path="file"
|
|
|
+
|
|
|
+ # 使用curl上传文件并获取响应
|
|
|
+ local response=$(curl -k -X POST -F "file=@$file_path" "$upload_url")
|
|
|
+
|
|
|
+ # 解析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
|
|
|
- curl -k -X POST -F "file=@$file_path" -F "oss_path=$oss_path" https://web_history.tianyunperfect.cn/oss/upload_file
|
|
|
|
|
|
- file_name=$(basename "$file_path")
|
|
|
+ # 获取文件名
|
|
|
+ local file_name=$(basename "$file_path")
|
|
|
echo ''
|
|
|
- echo "https://alist.tianyunperfect.cn/oss_gang/$oss_path/$file_name"
|
|
|
- echo "https://tianyunperfect.oss-cn-hongkong.aliyuncs.com/$oss_path/$file_name"
|
|
|
+ echo "https://alist.tianyunperfect.cn/oss_jing1/$file_name"
|
|
|
+ echo "https://oss_b_1.tianyunperfect.cn/$file_name"
|
|
|
+ echo "https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/$file_name"
|
|
|
+}
|
|
|
+
|
|
|
+# 上传文件到指定的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"
|
|
|
}
|