Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#Requires -Version 7
# For simplicity's sake, this only accepts uploading 1 file at a time
Param(
[Parameter(ValueFromPipeline)][string] $File,
[string] $Token,
[int] $AlbumID,
[switch] $Silent = $False
)
IF (!$File) {
Write-Error "Missing -File argument."
Exit 1
}
# Constants
Set-Variable MAX_RETRIES -Option Constant -Value 3
# Build request headers dictionary
$Headers = @{
"Accept" = "application/json"
"token" = $Token
"albumid" = "$AlbumID"
}
$Form = @{
"files[]" = (Get-Item -Path $File)
}
# Upload file within For-loop
For ($i = 1; $i -le $MAX_RETRIES; $i++) {
If (!$Silent) {
Write-Output "Uploading ($i/$MAX_RETRIES)..."
}
$Request = (Invoke-WebRequest `
-Method "POST" `
-Uri "https://safe.fiery.me/api/upload" `
-Headers $Headers `
-Form $Form)
# Parse response body as JSON
$Parsed = $Request.Content | Out-String | ConvertFrom-Json
# Break For-loop early if successful
If ($Parsed.success) {
Break
}
}
# Output URL
Write-Output $Parsed.files.url
@BobbyWibowo
Copy link
Author

BobbyWibowo commented Sep 10, 2022

Requires PowerShell 7+

Sample usage with foo_discord_rich > Advanced > Artwork upload command:

pwsh.exe -Command "\path\to\SimpleUpload.ps1 -File $Input -Token YOUR_TOKEN_HERE -AlbumID YOUR_ALBUM_ID_HERE -Silent"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment