Updated to accept first argument as a URL. E.g. https://raiza.dev/Downloads/y2k12-something.txt

This commit is contained in:
Yuuki Chan 2024-07-18 11:59:29 +09:00
parent b91579f15c
commit df5dc8240d
2 changed files with 39 additions and 3 deletions

View file

@ -4,6 +4,5 @@
<OpenFolders /> <OpenFolders />
<OpenFiles> <OpenFiles>
<File>downloader.ps1</File> <File>downloader.ps1</File>
<File>Startup.pss</File>
</OpenFiles> </OpenFiles>
</ProjectState> </ProjectState>

View file

@ -60,5 +60,42 @@ class Catbox {
} }
} }
$catbox = [Catbox]::new() If ($args.Length -eq 1 -and $args[0] -and $args[0].ToString().Contains("https://raiza.dev/Downloads/y2k12-") -and $args[0].ToString().EndsWith(".txt"))
$catbox.Download() {
$statuscode = 404
$file = $null
try
{
$statuscode = (Invoke-WebRequest -Uri $args[0] -UseBasicParsing | Select-Object StatusCode).StatusCode
$file = $args[0].Substring($args[0].IndexOf(".dev/Downloads/") + 15)
Write-Host "Downloading" $file "..."
}
catch
{
$statuscode = 404
$file = $null
}
finally
{
If ($statuscode -eq 200 -and $file)
{
Invoke-WebRequest -Uri $args[0] -OutFile $file
Write-Host ""
$catbox = [Catbox]::new()
$catbox.Download()
}
Else
{
Write-Host "File not found on the server."
}
}
}
Else
{
$catbox = [Catbox]::new()
$catbox.Download()
}