feat: replace browser login with imported Reddit sessions
This commit is contained in:
1 parent
2b0545afcf
commit
c483c7b8be
76 files changed
+2048
-2828
No files matched your search
@@ -0,0 +1,52 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Read-EnvFile([string]$Path) {
|
||||
$values = @{}
|
||||
Get-Content -LiteralPath $Path | ForEach-Object {
|
||||
if ($_ -match '^\s*([^#=]+)=(.*)$') {
|
||||
$values[$matches[1].Trim()] = $matches[2].Trim().Trim('"')
|
||||
}
|
||||
}
|
||||
return $values
|
||||
}
|
||||
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$deploy = Read-EnvFile (Join-Path $root '.env')
|
||||
foreach ($required in @('DOKPLOY_URL', 'DOKPLOY_API_KEY')) {
|
||||
if (-not $deploy[$required]) { throw "Missing $required in .env" }
|
||||
}
|
||||
|
||||
$headers = @{ 'x-api-key' = $deploy.DOKPLOY_API_KEY; Accept = 'application/json' }
|
||||
$base = $deploy.DOKPLOY_URL.TrimEnd('/')
|
||||
$core = Invoke-RestMethod -Uri "$base/api/environment.byProjectId?projectId=5hj5VzXYE0fe3SKOx7y5g" -Headers $headers
|
||||
$reddit = @($core.compose | Where-Object { $_.name -eq 'reddit' })[0]
|
||||
if (-not $reddit.env) { throw 'Core/production Reddit service environment was not found' }
|
||||
|
||||
$remote = @{}
|
||||
$reddit.env -split "`n" | ForEach-Object {
|
||||
if ($_ -match '^([^=]+)=(.*)$') { $remote[$matches[1]] = $matches[2] }
|
||||
}
|
||||
foreach ($required in @('OPENROUTER_API_KEY')) {
|
||||
if (-not $remote[$required]) { throw "Deployed environment is missing $required" }
|
||||
}
|
||||
|
||||
$previous = @{}
|
||||
foreach ($entry in $remote.GetEnumerator()) {
|
||||
$previous[$entry.Key] = [Environment]::GetEnvironmentVariable($entry.Key, 'Process')
|
||||
[Environment]::SetEnvironmentVariable($entry.Key, $entry.Value, 'Process')
|
||||
}
|
||||
$previous['WEB_DASHBOARD_TOKEN'] = [Environment]::GetEnvironmentVariable('WEB_DASHBOARD_TOKEN', 'Process')
|
||||
[Environment]::SetEnvironmentVariable('WEB_DASHBOARD_TOKEN', 'create01', 'Process')
|
||||
|
||||
$logDirectory = Join-Path $root 'data'
|
||||
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
||||
$stdout = Join-Path $logDirectory 'local-dev.stdout.log'
|
||||
$stderr = Join-Path $logDirectory 'local-dev.stderr.log'
|
||||
$process = Start-Process -FilePath 'npm.cmd' -ArgumentList 'run', 'dev' -WorkingDirectory $root -WindowStyle Hidden -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru
|
||||
|
||||
foreach ($name in $previous.Keys) {
|
||||
[Environment]::SetEnvironmentVariable($name, $previous[$name], 'Process')
|
||||
}
|
||||
|
||||
Write-Output "Started local RedditBot process $($process.Id)."
|
||||
Write-Output "Logs: $stdout"
|
||||
Reference in new issue
Block a user