Skip to content

Commit

Permalink
simplify how the curl command is determined
Browse files Browse the repository at this point in the history
thanks to @FederAndInk for the help yet again :D
  • Loading branch information
NielsPilgaard committed Aug 2, 2022
1 parent 88853f0 commit 2825f80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 53 deletions.
9 changes: 6 additions & 3 deletions get-game-versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ function Validate-SecretsFile {

if ($null -eq $IsWindows -or $IsWindows) {
# The script is running on Windows, use curl.exe
curl.exe -H X-Api-Token:$CURSEFORGE_TOKEN https://minecraft.curseforge.com/api/game/versions >> game-versions.json
} else {
curl -H X-Api-Token:$CURSEFORGE_TOKEN https://minecraft.curseforge.com/api/game/versions >> game-versions.json
$curl = "curl.exe"
}
else {
$curl = "curl"
}

& $curl -H X-Api-Token:$CURSEFORGE_TOKEN https://minecraft.curseforge.com/api/game/versions >> game-versions.json
71 changes: 21 additions & 50 deletions modpack-uploader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ function Test-ForDependencies {
throw "7zip not command available. Please follow the instructions above."
}

if ($IsWindows) {
$isCurlAvailable = Get-Command curl.exe
}
else {
$isCurlAvailable = Get-Command curl
}
$isCurlAvailable = Get-Command $curl

if (-not $isCurlAvailable) {
Clear-Host
Expand All @@ -69,7 +64,7 @@ function Test-ForDependencies {
Write-Host
Write-Host "When you're done, rerun this script.`n"

throw "curl or curl.exe command not available. Please follow the instructions above."
throw "curl not available. Please follow the instructions above."
}
}

Expand Down Expand Up @@ -242,26 +237,15 @@ function Push-ClientFiles {
Write-Host "Uploading client files to https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" -ForegroundColor Green
Write-Host

if ($IsWindows) {
$response = curl.exe `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$CLIENT_METADATA `
-F file=@"$CLIENT_ZIP_NAME.zip" `
--progress-bar | ConvertFrom-Json
}
else {
$response = curl `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$CLIENT_METADATA `
-F file=@"$CLIENT_ZIP_NAME.zip" `
--progress-bar | ConvertFrom-Json
}
$response = & $curl `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$CLIENT_METADATA `
-F file=@"$CLIENT_ZIP_NAME.zip" `
--progress-bar | ConvertFrom-Json


$clientFileReturnId = $response.id

Expand Down Expand Up @@ -345,27 +329,14 @@ function Push-ServerFiles {
Write-Host "Uploading server files..." -ForegroundColor Cyan
Write-Host

if ($IsWindows) {

$serverFileResponse = curl.exe `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$SERVER_METADATA `
-F file=@$serverFilePath `
--progress-bar | ConvertFrom-Json
}
else {
$serverFileResponse = curl `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$SERVER_METADATA `
-F file=@$serverFilePath `
--progress-bar | ConvertFrom-Json
}
$serverFileResponse = & $curl `
--url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" `
--user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" `
-H "Accept: application/json" `
-H X-Api-Token:$CURSEFORGE_TOKEN `
-F metadata=$SERVER_METADATA `
-F file=@$serverFilePath `
--progress-bar | ConvertFrom-Json

if ($serverFileResponse.errorCode) {
throw "Failed to upload server files: $serverFileResponse"
Expand Down Expand Up @@ -433,10 +404,10 @@ Set-Location $INSTANCE_ROOT

if ($null -eq $IsWindows -or $IsWindows) {
# The script is running on Windows, use curl.exe
$IsWindows = $true
$curl = "curl.exe"
}
else {
$IsWindows = $false
$curl = "curl"
}

Test-ForDependencies
Expand Down

0 comments on commit 2825f80

Please sign in to comment.