fix: normalize newlines for lyrics replacement

This commit is contained in:
2026-06-04 13:25:53 +02:00
parent cee3d24582
commit 0932357cdf
2 changed files with 14 additions and 3 deletions
+2 -1
View File
@@ -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() };
}
+12 -2
View File
@@ -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 };