|
@@ -8,12 +8,13 @@ import { TTS_RESPONSE_SPLIT } from '$lib/types';
|
|
// Helper functions
|
|
// Helper functions
|
|
//////////////////////////
|
|
//////////////////////////
|
|
|
|
|
|
-export const replaceTokens = (content, char, user) => {
|
|
|
|
|
|
+export const replaceTokens = (content, sourceIds, 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 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
|
|
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) {
|
|
content = content.replace(charToken, char);
|
|
content = content.replace(charToken, char);
|
|
@@ -36,6 +37,18 @@ export const replaceTokens = (content, char, user) => {
|
|
return `<iframe src="${htmlUrl}" width="100%" frameborder="0" onload="this.style.height=(this.contentWindow.document.body.scrollHeight+20)+'px';"></iframe>`;
|
|
return `<iframe src="${htmlUrl}" width="100%" frameborder="0" onload="this.style.height=(this.contentWindow.document.body.scrollHeight+20)+'px';"></iframe>`;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
+ // Remove sourceIds from the content and replace them with <source_id>...</source_id>
|
|
|
|
+ if (Array.isArray(sourceIds)) {
|
|
|
|
+ sourceIds.forEach((sourceId) => {
|
|
|
|
+ // Create a token based on the exact `[sourceId]` string
|
|
|
|
+ const sourceToken = `\\[${sourceId}\\]`; // Escape special characters for RegExp
|
|
|
|
+ const sourceRegex = new RegExp(sourceToken, 'g'); // Match all occurrences of [sourceId]
|
|
|
|
+
|
|
|
|
+ content = content.replace(sourceRegex, `<source_id data="${sourceId}" />`);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
return content;
|
|
return content;
|
|
};
|
|
};
|
|
|
|
|