|
@@ -1,5 +1,6 @@
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
import sha256 from 'js-sha256';
|
|
|
+import { WEBUI_BASE_URL } from '$lib/constants';
|
|
|
|
|
|
//////////////////////////
|
|
|
// Helper functions
|
|
@@ -36,6 +37,8 @@ export const sanitizeResponseContent = (content: string) => {
|
|
|
export const replaceTokens = (content, char, user) => {
|
|
|
const charToken = /{{char}}/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
|
|
|
if (char !== undefined && char !== null) {
|
|
@@ -47,6 +50,18 @@ export const replaceTokens = (content, char, 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;
|
|
|
};
|
|
|
|