feat: import/export community

This commit is contained in:
Timothy J. Baek 2024-06-26 00:22:26 -07:00
parent bc5e39d31b
commit 0e7db89117
4 changed files with 64 additions and 4 deletions

View File

@ -43,8 +43,26 @@
let showDeleteConfirm = false;
const shareHandler = async (tool) => {
console.log(tool);
const shareHandler = async (item) => {
toast.success($i18n.t('Redirecting you to OpenWebUI Community'));
const url = 'https://openwebui.com';
const tab = await window.open(`${url}/tools/create`, '_blank');
// Define the event handler function
const messageHandler = (event) => {
if (event.origin !== url) return;
if (event.data === 'loaded') {
tab.postMessage(JSON.stringify(item), '*');
// Remove the event listener after handling the message
window.removeEventListener('message', messageHandler);
}
};
window.addEventListener('message', messageHandler, false);
console.log(item);
};
const cloneHandler = async (func) => {

View File

@ -39,8 +39,26 @@
let showDeleteConfirm = false;
const shareHandler = async (tool) => {
console.log(tool);
const shareHandler = async (item) => {
toast.success($i18n.t('Redirecting you to OpenWebUI Community'));
const url = 'https://openwebui.com';
const tab = await window.open(`${url}/tools/create`, '_blank');
// Define the event handler function
const messageHandler = (event) => {
if (event.origin !== url) return;
if (event.data === 'loaded') {
tab.postMessage(JSON.stringify(item), '*');
// Remove the event listener after handling the message
window.removeEventListener('message', messageHandler);
}
};
window.addEventListener('message', messageHandler, false);
console.log(item);
};
const cloneHandler = async (tool) => {

View File

@ -36,6 +36,18 @@
};
onMount(() => {
window.addEventListener('message', async (event) => {
if (
!['https://openwebui.com', 'https://www.openwebui.com', 'http://localhost:9999'].includes(
event.origin
)
)
return;
func = JSON.parse(event.data);
console.log(func);
});
if (sessionStorage.function) {
func = JSON.parse(sessionStorage.function);
sessionStorage.removeItem('function');

View File

@ -33,6 +33,18 @@
};
onMount(() => {
window.addEventListener('message', async (event) => {
if (
!['https://openwebui.com', 'https://www.openwebui.com', 'http://localhost:9999'].includes(
event.origin
)
)
return;
tool = JSON.parse(event.data);
console.log(tool);
});
if (sessionStorage.tool) {
tool = JSON.parse(sessionStorage.tool);
sessionStorage.removeItem('tool');