@@ -93,18 +93,92 @@ jobs:
9393 mapfile -t files < <(sort -n upload_list.txt | awk '{print $2}')
9494
9595 attach_api="${GITEE_API}/releases/${release_id}/attach_files"
96+ # 上传辅助函数:尝试多种参数形式
97+ upload_one() {
98+ local filepath="$1"
99+ local attempt ok http_code body tmp
100+ ok=0
101+ tmp=$(mktemp)
102+ # 依次尝试不同参数形式(不使用 -f,以便获取返回体进行判定)
103+ for attempt in 1 2 3 4 5 6; do
104+ case "$attempt" in
105+ 1)
106+ echo " - try1: form token + files=@"$filepath""
107+ http_code=$(curl --http1.1 -4 -sS -X POST \
108+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
109+ -F access_token="${GITEE_TOKEN}" \
110+ -F files=@"$filepath" \
111+ -o "$tmp" -w "%{http_code}" \
112+ "$attach_api")
113+ ;;
114+ 2)
115+ echo " - try2: form token + file=@"$filepath""
116+ http_code=$(curl --http1.1 -4 -sS -X POST \
117+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
118+ -F access_token="${GITEE_TOKEN}" \
119+ -F file=@"$filepath" \
120+ -o "$tmp" -w "%{http_code}" \
121+ "$attach_api")
122+ ;;
123+ 3)
124+ echo " - try3: form token + files[]=@"$filepath""
125+ http_code=$(curl --http1.1 -4 -sS -X POST \
126+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
127+ -F access_token="${GITEE_TOKEN}" \
128+ -F 'files[]=@'"$filepath" \
129+ -o "$tmp" -w "%{http_code}" \
130+ "$attach_api")
131+ ;;
132+ 4)
133+ echo " - try4: url token + files=@"$filepath""
134+ http_code=$(curl --http1.1 -4 -sS -X POST \
135+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
136+ -F files=@"$filepath" \
137+ -o "$tmp" -w "%{http_code}" \
138+ "$attach_api?access_token=${GITEE_TOKEN}")
139+ ;;
140+ 5)
141+ echo " - try5: url token + file=@"$filepath""
142+ http_code=$(curl --http1.1 -4 -sS -X POST \
143+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
144+ -F file=@"$filepath" \
145+ -o "$tmp" -w "%{http_code}" \
146+ "$attach_api?access_token=${GITEE_TOKEN}")
147+ ;;
148+ 6)
149+ echo " - try6: url token + files[]=@"$filepath""
150+ http_code=$(curl --http1.1 -4 -sS -X POST \
151+ --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
152+ -F 'files[]=@'"$filepath" \
153+ -o "$tmp" -w "%{http_code}" \
154+ "$attach_api?access_token=${GITEE_TOKEN}")
155+ ;;
156+ esac
157+ body=$(head -c 256 "$tmp" || true)
158+ echo " http=$http_code body=${body}"
159+ if [ "$http_code" = "201" ]; then
160+ ok=1; break
161+ fi
162+ # 容错:若服务端提示已存在,视为成功
163+ if echo "$body" | grep -Eqi '已存在|already exists|exist'; then
164+ ok=1; break
165+ fi
166+ done
167+ rm -f "$tmp"
168+ [ "$ok" = "1" ]
169+ }
170+
96171 for f in "${files[@]}"; do
97172 name="$f"
98173 if echo " $existing " | grep -q " $name "; then
99174 echo "Skip $name (exists)"
100175 continue
101176 fi
102177 echo "Uploading $name ..."
103- # 使用 curl 表单上传,带重试
104- curl --http1.1 -4 -sS -f -X POST \
105- --retry ${CURL_RETRY} --retry-delay ${CURL_RETRY_DELAY} --connect-timeout 10 --max-time 1800 \
106- -F access_token="${GITEE_TOKEN}" \
107- -F files=@"$name" \
108- "$attach_api"
109- echo " -> uploaded"
178+ if upload_one "$name"; then
179+ echo " -> uploaded"
180+ else
181+ echo "Upload failed for $name after all attempts" >&2
182+ exit 1
183+ fi
110184 done
0 commit comments