fix: replace WebClient with curl.exe for APK upload (5min timeout)
WebClient.UploadData() has no configurable timeout and was silently timing out on 89MB uploads over Tailscale. curl.exe (built-in on Windows 10+) is used instead with --max-time 300 (5 minutes). Made-with: Cursor
This commit is contained in:
parent
2890b6cb6f
commit
7a20f161dd
|
|
@ -131,27 +131,20 @@ foreach ($apk in $apkFiles) {
|
||||||
$mb = [math]::Round($apk.Length / 1MB, 1)
|
$mb = [math]::Round($apk.Length / 1MB, 1)
|
||||||
Write-Host " Uploading: $($apk.Name) ($mb MB)..." -ForegroundColor Gray
|
Write-Host " Uploading: $($apk.Name) ($mb MB)..." -ForegroundColor Gray
|
||||||
|
|
||||||
$boundary = [System.Guid]::NewGuid().ToString()
|
|
||||||
$uploadUrl = "$GITEA_BASE_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$($release.id)/assets?name=$($apk.Name)"
|
$uploadUrl = "$GITEA_BASE_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$($release.id)/assets?name=$($apk.Name)"
|
||||||
|
|
||||||
$fileBytes = [System.IO.File]::ReadAllBytes($apk.FullName)
|
# curl.exe (Windows 10+ 内蔵) を使用: WebClient より大容量ファイルに強く、
|
||||||
$enc = [System.Text.Encoding]::UTF8
|
# --max-time で明示的なタイムアウト設定が可能
|
||||||
|
$curlOutput = curl.exe -s --max-time 300 `
|
||||||
|
-X POST $uploadUrl `
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" `
|
||||||
|
-F "attachment=@$($apk.FullName);type=application/octet-stream"
|
||||||
|
|
||||||
$bodyParts = [System.Collections.Generic.List[byte]]::new()
|
if ($LASTEXITCODE -ne 0) {
|
||||||
$header = "--$boundary`r`nContent-Disposition: form-data; name=`"attachment`"; filename=`"$($apk.Name)`"`r`nContent-Type: application/octet-stream`r`n`r`n"
|
throw "curl upload failed (exit code $LASTEXITCODE)"
|
||||||
$bodyParts.AddRange($enc.GetBytes($header))
|
}
|
||||||
$bodyParts.AddRange($fileBytes)
|
|
||||||
$footer = "`r`n--$boundary--`r`n"
|
|
||||||
$bodyParts.AddRange($enc.GetBytes($footer))
|
|
||||||
$bodyArray = $bodyParts.ToArray()
|
|
||||||
|
|
||||||
$wc = New-Object System.Net.WebClient
|
$json = $curlOutput | ConvertFrom-Json
|
||||||
$wc.Headers.Add("Authorization", "token $GITEA_TOKEN")
|
|
||||||
$wc.Headers.Add("Content-Type", "multipart/form-data; boundary=$boundary")
|
|
||||||
$result = $wc.UploadData($uploadUrl, "POST", $bodyArray)
|
|
||||||
$wc.Dispose()
|
|
||||||
|
|
||||||
$json = [System.Text.Encoding]::UTF8.GetString($result) | ConvertFrom-Json
|
|
||||||
$downloadUrls[$apk.BaseName] = $json.browser_download_url
|
$downloadUrls[$apk.BaseName] = $json.browser_download_url
|
||||||
Write-Host " OK: $($json.browser_download_url)" -ForegroundColor Green
|
Write-Host " OK: $($json.browser_download_url)" -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue