mirror of
https://github.com/open-webui/open-webui
synced 2024-11-28 15:05:07 +00:00
refac
This commit is contained in:
parent
e3668a2f1c
commit
7b64b40270
@ -214,7 +214,7 @@
|
||||
}
|
||||
} catch (e) {
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
@ -6,7 +6,17 @@ import sha256 from 'js-sha256';
|
||||
//////////////////////////
|
||||
|
||||
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(/<$/, '')
|
||||
@ -14,6 +24,13 @@ export const sanitizeResponseContent = (content: string) => {
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user