|
# $env:POLLINATIONSAI_API_KEY = "sk_..." |
|
|
|
|
|
Start-PodeServer { |
|
|
|
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging -Levels Error, Warning, Informational |
|
New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging |
|
|
|
|
|
Add-PodeEndpoint -Address localhost -Port 8080 -Protocol Http |
|
|
|
# set the engine to use and render Pode files |
|
Set-PodeViewEngine -Type Pode |
|
|
|
# import the PollinationsAI module into isolated scopes (this will make them available to all routes) |
|
Import-PodeModule -Path .\Modules\PollinationsAI\init.ps1 |
|
|
|
|
|
# Fun ... open this as a new window in windows |
|
#Show-PodeGui -Title 'Pode Desktop Application' -ResizeMode 'NoResize' |
|
|
|
|
|
Add-PodeRoute -Method Get -Path '/' -ScriptBlock { |
|
|
|
$query = $WebEvent.Query['query'] |
|
|
|
Write-PodeViewResponse -Path 'index' -Data @{ |
|
'query' = $query |
|
} |
|
} |
|
|
|
Add-PodeRoute -Method Get -Path '/ping' -ScriptBlock { |
|
Write-PodeJsonResponse -Value @{ value = 'pong' } |
|
} |
|
|
|
# #! shows full path to folder in output !! Files do not open and 404 |
|
# Add-PodeRoute -Method Get -Path '/files' -ScriptBlock { |
|
# Write-PodeDirectoryResponse -Path .\public\cache |
|
# } |
|
#* Better use this. |
|
Add-PodeStaticRoute -Path '/files' -Source .\public\cache -FileBrowser |
|
|
|
|
|
Add-PodeRoute -Method Get -Path '/create' -ScriptBlock { |
|
$prompt = $WebEvent.Query['prompt'] ?? "a very cute cat" |
|
|
|
$pathAbs = PollinationsAI-Img "$prompt" -bypass -out (".\public\cache\" + (Get-Date).Ticks + (Get-Random)) |
|
|
|
$path = (Resolve-Path -Path $pathAbs -Relative -RelativeBasePath ($PSScriptRoot + "\public\")) -replace '\\', '/' |
|
|
|
Write-PodeHtmlResponse "<style>body{place-content:center;justify-self:center;}</style> <div><h1>`"$prompt`"</h1><img src=`"$path`" /></div>" |
|
} |
|
|
|
Add-PodeRoute -Method Get -Path '/img' -ScriptBlock { |
|
$details = PollinationsAI-Img "a very cute cat" -bypass -out (".\public\cache\" + (Get-Date).Ticks + (Get-Random)) -Details |
|
|
|
# save headers and info |
|
$details | select -ExcludeProperty Content | ConvertTo-Json | Out-File -FilePath ($details.FilePath + ".details.json") |
|
|
|
#! 404 !!! --> THIS DOES NOT WORK: File in -Path not found ... so what is -Data for ? |
|
#Write-PodeFileResponse -Data $details.Content -Path ($details.FilePath | Split-Path -Leaf) -ContentType "image/jpg" #-ContentType $details.Headers.'Content-Type'[0] |
|
|
|
Add-PodeHeader -Name "Content-Disposition" -Value "inline; filename=`"$($details.FilePath | Split-Path -Leaf)`"" |
|
Write-PodeTextResponse -Bytes $details.Content -ContentType $details.Headers.'Content-Type'[0] |
|
} |
|
} |