Skip to content

Commit

Permalink
Add BuildNPURI function for dynamic URL construction and update Dynam…
Browse files Browse the repository at this point in the history
…icLoading script
  • Loading branch information
Nillth committed Nov 19, 2024
1 parent 806d71e commit d658dcc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
31 changes: 31 additions & 0 deletions src/Private/BuildNPURI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function BuildNPURI {
param (
[string]$Path,
[switch]$NPE,
[string]$URLServerAPI,
[string]$URLServerNPE,
[hashtable]$QueryParameters
)

if ([uri]::IsWellFormedUriString($Path, [System.UriKind]::Absolute)) {
return $Path
}

# Base URL depending on the NPE flag
$BaseURL = if ($NPE) { $URLServerNPE } else { $URLServerAPI }
$FullPath = [System.IO.Path]::Combine($BaseURL.TrimEnd('/'), $Path.TrimStart('/'))

# Add query parameters
if ($QueryParameters) {
$UriBuilder = [System.UriBuilder]$FullPath
$QueryString = [System.Web.HttpUtility]::ParseQueryString($UriBuilder.Query)
foreach ($key in $QueryParameters.Keys) {
if (-not $QueryString[$key]) {
$QueryString[$key] = $QueryParameters[$key]
}
}
$UriBuilder.Query = $QueryString.ToString()
return $UriBuilder.Uri.AbsoluteUri
}
return $FullPath
}
5 changes: 2 additions & 3 deletions src/Resources/BuildFiles/Scripts/DynamicLoading.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $DynamicLoading = @'
[System.IO.DirectoryInfo]$publicFunctionsPath = Join-Path $modulePath -ChildPath 'Public'
[System.IO.DirectoryInfo]$privateFunctionsPath = Join-Path $modulePath -ChildPath 'Private'
[System.IO.DirectoryInfo]$classesPath = Join-Path $modulePath -ChildPath 'Classes'
Write-Warning "$PSScriptRoot"
$aliases = @()
[regex]$FunctionName = [regex]::new('(?<=function )([\w]+-[\w]+)(?>[\s]+\{)', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
Expand All @@ -18,9 +17,9 @@ if ($publicFunctionsPath.Exists) {
$alias = Get-Alias -Definition $function -ErrorAction SilentlyContinue
if ($alias) {
$aliases += $alias
Export-ModuleMember -Function $function -Alias $alias -Verbose
Export-ModuleMember -Function $function -Alias $alias
} else {
Export-ModuleMember -Function "$($function)" -Verbose
Export-ModuleMember -Function "$($function)"
}
}
}
Expand Down

0 comments on commit d658dcc

Please sign in to comment.