It's not complete yet, and I've had some trouble interpreting how to upload the new releases from the official documentation here https://wiki.factorio.com/Mod_upload_API
I'm not a python guy so the example given is difficult to interpret for me, but this is my best answer as to what the python code is trying to do, however this code does not upload correctly:
Code: Select all
function Push-FactorioMod {
param (
[Parameter(Mandatory=$true)][string]$APIKey,
[Parameter(Mandatory=$true)][string]$Name,
[Parameter(Mandatory=$true)][System.IO.FileInfo]$Path
)
try {
$Response = Invoke-RestMethod -Uri "https://mods.factorio.com/api/v2/mods/releases/init_upload" -Method POST -Body @{ mod = $Name } -Headers @{ Authorization = "Bearer $APIKey" }
} catch {
return $_
}
try {
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$body = New-Object System.Text.StringBuilder
[void]$body.AppendLine("--$boundary")
[void]$body.AppendLine("Content-Disposition: form-data; name=`"file`"; filename=`"$($Path.Name)`"")
[void]$body.AppendLine("Content-Type: application/zip$LF")
[void]$body.AppendLine([System.Text.Encoding]::Default.GetString([System.IO.File]::ReadAllBytes($Path.FullName)))
[void]$body.AppendLine("--$boundary--$LF")
$body.ToString()
return Invoke-RestMethod -Uri $Response.upload_url -Method POST -ContentType "multipart/form-data; boundary=$boundary" -Body $body.ToString()
} catch {
return $_
}
}
Code: Select all
Invoke-RestMethod:
Line |
26 | … $response = Invoke-RestMethod -Uri $response.upload_url -Method Post …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| { "error": "Unknown", "message": "Unknown error, please try again later." }
Code: Select all
--aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
Content-Disposition: form-data; name="file"; filename="mod-name_1.0.0.zip"
Content-Type: application/octet-stream
<binary-data-here>
--aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee--