From b6dcc131d3aa3a5faea7c82de9ebb917fa907e17 Mon Sep 17 00:00:00 2001 From: Severian Date: Thu, 13 Feb 2025 14:40:10 +0800 Subject: [PATCH] chore: sigh --- src/app/api/proxy/route.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/app/api/proxy/route.ts b/src/app/api/proxy/route.ts index d22c037..63cfd58 100644 --- a/src/app/api/proxy/route.ts +++ b/src/app/api/proxy/route.ts @@ -39,25 +39,32 @@ interface PersonaMatch { } function findTagsBetween(content: string, startMarker: string, endMarker: string): PersonaMatch[] { - const startIdx = content.indexOf(`<${startMarker}>`); + const startMarkerTag = `<${startMarker}>`; + const endMarkerTag = `<${endMarker}>`; + + const startIdx = content.indexOf(startMarkerTag); if (startIdx === -1) return []; - const endIdx = content.indexOf(`<${endMarker}>`); + const endIdx = content.indexOf(endMarkerTag); if (endIdx === -1) return []; - const section = content.slice(startIdx + startMarker.length + 2, endIdx); + const section = content.slice(startIdx, endIdx); + console.log("Section found:", section); + const matches: PersonaMatch[] = []; - const tagPattern = /<([^/>][^>]*)>([^]*?)<\/\1>/g; + const tagPattern = /<([^/>\s][^>]*)>([^]*?)<\/\1>/g; let match; while ((match = tagPattern.exec(section)) !== null) { + console.log("Found match:", match[1], match[2].substring(0, 50) + "..."); matches.push({ - tag: match[1], + tag: match[1].trim(), content: match[2].trim() }); } + console.log("Total matches found:", matches.length); return matches; }