fix: normalize newlines for lyrics replacement
This commit is contained in:
+2
-1
@@ -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
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user