feat: import tools

This commit is contained in:
Timothy J. Baek 2024-06-10 21:38:29 -07:00
parent 1611a3aa70
commit ca8be1ee4a

View File

@ -8,7 +8,7 @@
import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts'; import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { deleteToolById, exportTools, getTools } from '$lib/apis/tools'; import { createNewTool, deleteToolById, exportTools, getTools } from '$lib/apis/tools';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -186,8 +186,18 @@
const reader = new FileReader(); const reader = new FileReader();
reader.onload = async (event) => { reader.onload = async (event) => {
const tools = JSON.parse(event.target.result); const _tools = JSON.parse(event.target.result);
console.log(tools); console.log(_tools);
for (const tool of _tools) {
const res = await createNewTool(localStorage.token, tool).catch((error) => {
toast.error(error);
return null;
});
}
toast.success('Tool imported successfully');
tools.set(await getTools(localStorage.token));
}; };
reader.readAsText(importFiles[0]); reader.readAsText(importFiles[0]);