diff --git a/server.mjs b/server.mjs index 98efad5..fb3875d 100644 --- a/server.mjs +++ b/server.mjs @@ -370,7 +370,8 @@ function handleConfig(req, res) { if (envLinks.trim()) { // Expected format: "Kling AI=https://klingai.com,Luma=https://lumalabs.ai" videoAiLinks = envLinks.split(',').map(part => { - const idx = part.indexOf('='); + const sep = part.includes('=') ? '=' : '|'; + const idx = part.indexOf(sep); if (idx > 0) { return { name: part.slice(0, idx).trim(), url: part.slice(idx + 1).trim() }; } diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index 0f38877..61d0a66 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -269,8 +269,18 @@ export function HomePage() { let merged: SongAssets; if (isPartialLyrics) { // Replace only the selected text in the existing lyrics - const newPartial = (result as any).lyrics || (result as any).text || String(result); - const replaced = assets.lyrics.replace(selectedText, newPartial); + let newPartial = (result as any).lyrics || (result as any).text || String(result); + // Cleanup quotes or markdown if the LLM leaked them + newPartial = newPartial.replace(/^```[a-z]*\n/gi, '').replace(/\n```$/g, '').trim(); + if (newPartial.startsWith('"') && newPartial.endsWith('"')) { + newPartial = newPartial.slice(1, -1).trim(); + } + + // Normalize newlines to prevent replace() from failing due to \r\n vs \n + const normalizedAssetsLyrics = assets.lyrics.replace(/\r\n/g, '\n'); + const normalizedSelected = selectedText.replace(/\r\n/g, '\n'); + const replaced = normalizedAssetsLyrics.replace(normalizedSelected, newPartial); + merged = { ...assets, lyrics: replaced }; } else { merged = { ...assets, ...result };