Upload browser-downloaded Suno WAVs to companion
This commit is contained in:
@@ -248,6 +248,24 @@ function Add-TracksToQueue {
|
||||
}
|
||||
}
|
||||
|
||||
function Save-UploadedTrack {
|
||||
param($Payload)
|
||||
|
||||
if (-not $Payload.track) { throw "track is required" }
|
||||
if (-not $Payload.wavBase64) { throw "wavBase64 is required" }
|
||||
|
||||
$track = $Payload.track
|
||||
$id = "$($track.id)".Trim()
|
||||
if (-not $id) { $id = Get-Date -Format "yyyyMMdd-HHmmssfff" }
|
||||
|
||||
$wavPath = Join-Path $inbox ("suno-upload-{0}.wav" -f $id)
|
||||
$bytes = [Convert]::FromBase64String("$($Payload.wavBase64)")
|
||||
[IO.File]::WriteAllBytes($wavPath, $bytes)
|
||||
$track | Add-Member -NotePropertyName "localWavPath" -NotePropertyValue $wavPath -Force
|
||||
|
||||
return Add-TracksToQueue @($track) "$($Payload.pageUrl)"
|
||||
}
|
||||
|
||||
function Get-ExistingSunoIds {
|
||||
param([string]$Root)
|
||||
|
||||
@@ -394,6 +412,20 @@ try {
|
||||
continue
|
||||
}
|
||||
|
||||
if ($request.Method -eq "POST" -and $request.Path -eq "/upload-track") {
|
||||
$payload = $request.Body | ConvertFrom-Json
|
||||
$result = Save-UploadedTrack $payload
|
||||
Write-Host "Upload queue update: added=$($result.added), queued=$($result.queued), active=$($result.active)"
|
||||
Write-Response $stream 200 "OK" (@{
|
||||
ok = $true
|
||||
added = $result.added
|
||||
skipped = $result.skipped
|
||||
queued = $result.queued
|
||||
active = $result.active
|
||||
} | ConvertTo-Json -Compress)
|
||||
continue
|
||||
}
|
||||
|
||||
Write-Response $stream 404 "Not Found" (@{ ok = $false; error = "not found" } | ConvertTo-Json -Compress)
|
||||
} catch {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user