Skip to content

Instantly share code, notes, and snippets.

@Katzenwerfer
Last active February 15, 2023 18:30
Show Gist options
  • Save Katzenwerfer/1b980feb21ef76a8c11be4717654375f to your computer and use it in GitHub Desktop.
Save Katzenwerfer/1b980feb21ef76a8c11be4717654375f to your computer and use it in GitHub Desktop.
Send a request to Catbox's API using curl.exe
function Catbox-Request {
param (
[Parameter(
Mandatory,
Position = 0,
ValueFromPipeline = $true,
HelpMessage = "Path to a file or a media URL."
)]
[ValidateNotNullOrEmpty()]
[string]
[System.IO.FileInfo]$InputFile,
[parameter(
Mandatory,
Position = 1,
HelpMessage = "Type of request to be sent towards the API."
)]
[ValidateSet(
"fileupload",
"urlupload",
"deletefiles"
)]
[string]
$RequestType,
[parameter(
Position = 2,
HelpMessage = "To get your user hash go to: https://catbox.moe/user/manage.php.`nIf no hash is provided the request will be made anonymously and accountless."
)]
[string]
$UserHash
)
if ($RequestType -eq "fileupload") {
curl.exe -F "reqtype=$RequestType" -F "userhash=$UserHash" -F "fileToUpload=@$InputFile" https://catbox.moe/user/api.php
}
elseif ($RequestType -eq "urlupload") {
curl.exe -F "reqtype=$RequestType" -F "userhash=$UserHash" -F "url=$InputFile" https://catbox.moe/user/api.php
}
elseif ($RequestType -eq "deletefiles") {
curl.exe -F "reqtype=$RequestType" -F "userhash=$UserHash" -F "files=$InputFile" https://catbox.moe/user/api.php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment