This commit is contained in:
Timothy J. Baek 2024-06-19 15:26:35 -07:00
parent e3668a2f1c
commit 7b64b40270
2 changed files with 19 additions and 2 deletions

View File

@ -214,7 +214,7 @@
} }
} catch (e) { } catch (e) {
// Remove the failed doc from the files array // Remove the failed doc from the files array
files = files.filter((f) => f.name !== url); // files = files.filter((f) => f.name !== url);
toast.error(e); toast.error(e);
} }
}; };

View File

@ -6,7 +6,17 @@ import sha256 from 'js-sha256';
////////////////////////// //////////////////////////
export const sanitizeResponseContent = (content: string) => { export const sanitizeResponseContent = (content: string) => {
return content // First, temporarily replace valid <video> tags with a placeholder
const videoTagRegex = /<video\s+src="([^"]+)"\s+controls><\/video>/gi;
const placeholders: string[] = [];
content = content.replace(videoTagRegex, (_, src) => {
const placeholder = `{{VIDEO_${placeholders.length}}}`;
placeholders.push(`<video src="${src}" controls></video>`);
return placeholder;
});
// Now apply the sanitization to the rest of the content
content = content
.replace(/<\|[a-z]*$/, '') .replace(/<\|[a-z]*$/, '')
.replace(/<\|[a-z]+\|$/, '') .replace(/<\|[a-z]+\|$/, '')
.replace(/<$/, '') .replace(/<$/, '')
@ -14,6 +24,13 @@ export const sanitizeResponseContent = (content: string) => {
.replaceAll('<', '&lt;') .replaceAll('<', '&lt;')
.replaceAll('>', '&gt;') .replaceAll('>', '&gt;')
.trim(); .trim();
// Replace placeholders with original <video> tags
placeholders.forEach((placeholder, index) => {
content = content.replace(`{{VIDEO_${index}}}`, placeholder);
});
return content.trim();
}; };
export const replaceTokens = (content, char, user) => { export const replaceTokens = (content, char, user) => {