Update samy.ps1

This commit is contained in:
2025-12-09 23:23:14 -05:00
parent 889f750fd3
commit 2762758d63

View File

@@ -82,8 +82,8 @@ function Import-SamyModule {
- Fallback to .\<Name>
Remote (iwr | iex):
- Try .../module/<Name>?raw=1 first
- If that 404s, fallback to .../<Name>?raw=1
- Try .../module/<Name> first
- If that 404s, fallback to .../<Name>
#>
[CmdletBinding()]
param(
@@ -92,8 +92,8 @@ function Import-SamyModule {
# 1) Local dev mode: script saved to disk
if ($PSCommandPath) {
$moduleRoot = Join-Path -Path $PSScriptRoot -ChildPath 'module'
$localModulePath = Join-Path -Path $moduleRoot -ChildPath $Name
$moduleRoot = Join-Path -Path $PSScriptRoot -ChildPath 'module'
$localModulePath = Join-Path -Path $moduleRoot -ChildPath $Name
$localRootPath = Join-Path -Path $PSScriptRoot -ChildPath $Name
if (Test-Path $localModulePath) {
@@ -108,19 +108,18 @@ function Import-SamyModule {
}
# 2) Remote mode (iwr | iex): pull module from repo
$base = "$Script:SamyRepoBase/$Script:SamyBranch"
$base = "{0}/{1}" -f $Script:SamyRepoBase, $Script:SamyBranch
$primaryUrl = "$base/module/$Name?raw=1"
$fallbackUrl = "$base/$Name?raw=1"
$primaryUrl = "{0}/module/{1}" -f $base, $Name
$fallbackUrl = "{0}/{1}" -f $base, $Name
# Helper to download and load a URL
function Invoke-LoadUrl {
param(
[Parameter(Mandatory)][string]$Url,
[Parameter(Mandatory)][string]$ModuleName
)
$resp = Invoke-WebRequest -Uri $Url -UseBasicParsing -ErrorAction Stop
$resp = Invoke-WebRequest -Uri $Url -UseBasicParsing -ErrorAction Stop
$content = $resp.Content
if (-not $content) {
Write-Host ("[Error] Module {0} from {1} returned empty content." -f $ModuleName, $Url) -ForegroundColor Red
@@ -130,7 +129,7 @@ function Import-SamyModule {
}
try {
# Try /module/<Name>?raw=1 first
# Try /module/<Name> first
Invoke-LoadUrl -Url $primaryUrl -ModuleName $Name
}
catch [System.Net.WebException] {
@@ -141,7 +140,6 @@ function Import-SamyModule {
}
if ($statusCode -eq 404) {
# Fallback to root-level file
Write-Host ("[Info] Module {0} not found at {1} (404). Trying fallback {2}." -f $Name, $primaryUrl, $fallbackUrl) -ForegroundColor Yellow
try {
Invoke-LoadUrl -Url $fallbackUrl -ModuleName $Name
@@ -158,7 +156,7 @@ function Import-SamyModule {
}
catch {
if (-not ($_ -is [System.Net.WebException])) {
Write-Host ("[Error] Failed to load module {0} from {1}: {2}" -f $Name, $primaryUrl, $_.Exception.Message) -ForegroundColor Red
Write-Host ("[Error] Failed to load module {0}: {1}" -f $Name, $_.Exception.Message) -ForegroundColor Red
}
throw
}