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
d5b76b5e
"src/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "a030505a5065f787d210920a30174ab5457a9ffc"
Commit
d5b76b5e
authored
Jun 19, 2024
by
Timothy J. Baek
Browse files
enh: iframe support
parent
7b64b402
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
src/app.html
src/app.html
+6
-0
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+6
-3
src/lib/utils/index.ts
src/lib/utils/index.ts
+15
-0
No files found.
src/app.html
View file @
d5b76b5e
...
@@ -13,6 +13,12 @@
...
@@ -13,6 +13,12 @@
href=
"/opensearch.xml"
href=
"/opensearch.xml"
/>
/>
<script>
function
resizeIframe
(
obj
)
{
obj
.
style
.
height
=
obj
.
contentWindow
.
document
.
documentElement
.
scrollHeight
+
'
px
'
;
}
</script>
<script>
<script>
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
(()
=>
{
(()
=>
{
...
...
src/lib/components/chat/MessageInput.svelte
View file @
d5b76b5e
...
@@ -138,7 +138,7 @@
...
@@ -138,7 +138,7 @@
processFileItem(fileItem);
processFileItem(fileItem);
} else {
} else {
toast.error(
toast.error(
$i18n.t(`Unknown
F
ile
T
ype '{{file_type}}'
, but accepting and treating as plain text
`, {
$i18n.t(`Unknown
f
ile
t
ype '{{file_type}}'
. Proceeding with the file upload anyway.
`, {
file_type: file['type']
file_type: file['type']
})
})
);
);
...
@@ -158,8 +158,11 @@
...
@@ -158,8 +158,11 @@
}
}
} 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.id !== fileItem.id);
//
files = files.filter((f) => f.id !== fileItem.id);
toast.error(e);
toast.error(e);
fileItem.status = 'processed';
files = files;
}
}
};
};
...
@@ -214,7 +217,7 @@
...
@@ -214,7 +217,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 @
d5b76b5e
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
sha256
from
'
js-sha256
'
;
import
sha256
from
'
js-sha256
'
;
import
{
WEBUI_BASE_URL
}
from
'
$lib/constants
'
;
//////////////////////////
//////////////////////////
// Helper functions
// Helper functions
...
@@ -36,6 +37,8 @@ export const sanitizeResponseContent = (content: string) => {
...
@@ -36,6 +37,8 @@ export const sanitizeResponseContent = (content: string) => {
export
const
replaceTokens
=
(
content
,
char
,
user
)
=>
{
export
const
replaceTokens
=
(
content
,
char
,
user
)
=>
{
const
charToken
=
/{{char}}/gi
;
const
charToken
=
/{{char}}/gi
;
const
userToken
=
/{{user}}/gi
;
const
userToken
=
/{{user}}/gi
;
const
videoIdToken
=
/{{VIDEO_FILE_ID_
([
a-f0-9-
]
+
)
}}/gi
;
// Regex to capture the video ID
const
htmlIdToken
=
/{{HTML_FILE_ID_
([
a-f0-9-
]
+
)
}}/gi
;
// Regex to capture the HTML ID
// Replace {{char}} if char is provided
// Replace {{char}} if char is provided
if
(
char
!==
undefined
&&
char
!==
null
)
{
if
(
char
!==
undefined
&&
char
!==
null
)
{
...
@@ -47,6 +50,18 @@ export const replaceTokens = (content, char, user) => {
...
@@ -47,6 +50,18 @@ export const replaceTokens = (content, char, user) => {
content
=
content
.
replace
(
userToken
,
user
);
content
=
content
.
replace
(
userToken
,
user
);
}
}
// Replace video ID tags with corresponding <video> elements
content
=
content
.
replace
(
videoIdToken
,
(
match
,
fileId
)
=>
{
const
videoUrl
=
`
${
WEBUI_BASE_URL
}
/api/v1/files/
${
fileId
}
/content`
;
return
`<video src="
${
videoUrl
}
" controls></video>`
;
});
// Replace HTML ID tags with corresponding HTML content
content
=
content
.
replace
(
htmlIdToken
,
(
match
,
fileId
)
=>
{
const
htmlUrl
=
`
${
WEBUI_BASE_URL
}
/api/v1/files/
${
fileId
}
/content`
;
return
`<iframe src="
${
htmlUrl
}
" width="100%" frameborder="0" onload="this.style.height=(this.contentWindow.document.body.scrollHeight+20)+'px';"></iframe>`
;
});
return
content
;
return
content
;
};
};
...
...
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