Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
7b64b402
Commit
7b64b402
authored
Jun 19, 2024
by
Timothy J. Baek
Browse files
refac
parent
e3668a2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+1
-1
src/lib/utils/index.ts
src/lib/utils/index.ts
+18
-1
No files found.
src/lib/components/chat/MessageInput.svelte
View file @
7b64b402
...
@@ -214,7 +214,7 @@
...
@@ -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);
}
}
};
};
...
...
src/lib/utils/index.ts
View file @
7b64b402
...
@@ -6,7 +6,17 @@ import sha256 from 'js-sha256';
...
@@ -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) => {
...
@@ -14,6 +24,13 @@ export const sanitizeResponseContent = (content: string) => {
.
replaceAll
(
'
<
'
,
'
<
'
)
.
replaceAll
(
'
<
'
,
'
<
'
)
.
replaceAll
(
'
>
'
,
'
>
'
)
.
replaceAll
(
'
>
'
,
'
>
'
)
.
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
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment