Nice little directory browser :D
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: redirect map * list of directories that will 302 redirect on access * flash redirect notice banner for HTML responses * requires session cookies & JSON api users might not keep them, so no banner for them

+69
+34
Routes.ps1
··· 132 132 return $true 133 133 } 134 134 135 + Enable-PodeSessionMiddleware -Duration 120 -Extend 136 + 135 137 Add-PodeRouteGroup -Path /api -Routes { 136 138 Add-PodeRoute -Path /files -Method GET -ScriptBlock { 137 139 $Root = $using:Root 138 140 $Path = $WebEvent.Query.Path 139 141 $JoinedPath = Join-Path $Root $Path 140 142 143 + $Moved = $false 144 + (Get-PodeConfig).Utatane.RedirectMap.GetEnumerator() | % { 145 + if ($Path -eq $_.Key -or ($Path + '/') -eq $_.Key) { 146 + $Moved = @{ 147 + Url = ("/api/files?path=" + (_encode $_.Value)) 148 + } 149 + } 150 + } 151 + if ($Moved) { 152 + # api doesn't get a message since they probably aren't keeping the 153 + # cookie needed for session tracking 154 + 155 + Move-PodeResponseUrl @Moved 156 + return; 157 + } 158 + 141 159 if (-not (_check_path $Root $JoinedPath)) { 142 160 _warn "/api/files: query for $JoinedPath ($Path) refused!" 143 161 Set-PodeResponseStatus -Code 404 ··· 161 179 $Root = $using:Root 162 180 $Path = $WebEvent.Path ?? '/' 163 181 $JoinedPath = Get-Item -Lit (Join-Path $Root $Path) 182 + 183 + $Moved = $false 184 + (Get-PodeConfig).Utatane.RedirectMap.GetEnumerator() | % { 185 + if ($Path -eq $_.Key) { 186 + $Moved = @{ Url = $_.Value } 187 + } 188 + } 189 + if ($Moved) { 190 + Add-PodeFlashMessage -Name redirect-notice -Message @{ 191 + From = $Path 192 + To = $Moved.Url 193 + } 194 + 195 + Move-PodeResponseUrl @Moved 196 + return; 197 + } 164 198 165 199 if ($null -eq $JoinedPath) { 166 200 _warn "1failed: '$(Join-Path $Root $Path)' for query $($WebEvent.Query|convertto-json -compress)"
+3
Utatane.example.psd1
··· 3 3 DoNotServe = @( 4 4 # '*cookies.txt' 5 5 ) 6 + RedirectMap = @{ 7 + # '/old_path/' = '/new/path/' 8 + } 6 9 }
+11
public/style.css
··· 3338 3338 border-style: solid; 3339 3339 padding-inline: 0.5ch; 3340 3340 } 3341 + #redirect-notice code { 3342 + border-radius: var(--radius-sm); 3343 + background-color: var(--color-green-100); 3344 + padding-inline: calc(var(--spacing) * 2); 3345 + white-space: nowrap; 3346 + -webkit-user-select: all; 3347 + user-select: all; 3348 + @media (prefers-color-scheme: dark) { 3349 + background-color: var(--color-zinc-500); 3350 + } 3351 + } 3341 3352 #filetable { 3342 3353 width: 100%; 3343 3354 table-layout: fixed;
+10
tailwind/style.tw.css
··· 321 321 border border-solid rounded-sm; 322 322 } 323 323 324 + #redirect-notice code { 325 + @apply 326 + bg-green-100 327 + dark:bg-zinc-500 328 + px-2 329 + rounded-sm 330 + whitespace-nowrap 331 + select-all; 332 + } 333 + 324 334 #filetable { 325 335 @apply 326 336 w-full
+11
views/index.html.ps1
··· 19 19 $Path = $Data.Path 20 20 $JoinedPath = Join-Path $Root $Path 21 21 22 + $RedirectNotice = Get-PodeFlashMessage -Name redirect-notice 23 + 22 24 <# ### ### ### #> 23 25 24 26 . ./templates/frame.ps1 ` ··· 156 158 set dirs to `$('.directory').length 157 159 set my innerHTML to ```${dirs} $(_icon 'Directories' '📁') `${files} $(_icon 'Files' '📄')`` 158 160 "@ 161 + } 162 + } 163 + 164 + if ($null -ne $RedirectNotice) { 165 + span -Id redirect-notice -Class 'n-box flex text-center' { 166 + @" 167 + **Notice**: The path ``$($RedirectNotice.From)`` now redirects to ``$($RedirectNotice.To)``. 168 + Change any bookmarks for the old address to this new address, ``$($WebEvent.Request.Url)`` 169 + "@ | ConvertFrom-Markdown | % Html 159 170 } 160 171 } 161 172