2024-10-02 05:45:04 +00:00
|
|
|
<script lang="ts">
|
2024-10-04 19:35:06 +00:00
|
|
|
import Fuse from 'fuse.js';
|
2024-10-03 03:42:10 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2024-10-07 21:04:06 +00:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2024-10-20 07:36:43 +00:00
|
|
|
import { PaneGroup, Pane, PaneResizer } from 'paneforge';
|
2024-10-03 03:42:10 +00:00
|
|
|
|
2024-10-05 02:10:52 +00:00
|
|
|
import { onMount, getContext, onDestroy, tick } from 'svelte';
|
2024-10-02 05:45:04 +00:00
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { page } from '$app/stores';
|
2025-05-23 20:43:02 +00:00
|
|
|
import {
|
|
|
|
|
mobile,
|
|
|
|
|
showSidebar,
|
|
|
|
|
knowledge as _knowledge,
|
|
|
|
|
config,
|
|
|
|
|
user,
|
|
|
|
|
settings
|
|
|
|
|
} from '$lib/stores';
|
2024-10-02 14:44:07 +00:00
|
|
|
|
2025-04-23 07:05:15 +00:00
|
|
|
import {
|
|
|
|
|
updateFileDataContentById,
|
|
|
|
|
uploadFile,
|
|
|
|
|
deleteFileById,
|
|
|
|
|
getFileById
|
|
|
|
|
} from '$lib/apis/files';
|
2024-10-04 05:22:22 +00:00
|
|
|
import {
|
|
|
|
|
addFileToKnowledgeById,
|
|
|
|
|
getKnowledgeById,
|
2024-11-17 00:51:55 +00:00
|
|
|
getKnowledgeBases,
|
2024-10-04 05:22:22 +00:00
|
|
|
removeFileFromKnowledgeById,
|
2024-10-05 01:44:57 +00:00
|
|
|
resetKnowledgeById,
|
2024-10-04 07:46:32 +00:00
|
|
|
updateFileFromKnowledgeById,
|
2025-12-10 05:53:41 +00:00
|
|
|
updateKnowledgeById,
|
|
|
|
|
searchKnowledgeFilesById
|
2024-10-04 05:22:22 +00:00
|
|
|
} from '$lib/apis/knowledge';
|
2024-10-03 04:14:58 +00:00
|
|
|
import { blobToFile } from '$lib/utils';
|
2024-10-18 21:55:39 +00:00
|
|
|
|
|
|
|
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
2024-11-17 00:51:55 +00:00
|
|
|
import Files from './KnowledgeBase/Files.svelte';
|
2024-10-18 21:55:39 +00:00
|
|
|
import AddFilesPlaceholder from '$lib/components/AddFilesPlaceholder.svelte';
|
|
|
|
|
|
2024-11-17 00:51:55 +00:00
|
|
|
import AddContentMenu from './KnowledgeBase/AddContentMenu.svelte';
|
|
|
|
|
import AddTextContentModal from './KnowledgeBase/AddTextContentModal.svelte';
|
2024-10-05 02:38:24 +00:00
|
|
|
|
|
|
|
|
import SyncConfirmDialog from '../../common/ConfirmDialog.svelte';
|
2024-10-20 07:36:43 +00:00
|
|
|
import Drawer from '$lib/components/common/Drawer.svelte';
|
|
|
|
|
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
2024-11-17 04:47:45 +00:00
|
|
|
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
|
|
|
|
import AccessControlModal from '../common/AccessControlModal.svelte';
|
2025-06-25 17:42:18 +00:00
|
|
|
import Search from '$lib/components/icons/Search.svelte';
|
2025-09-14 06:42:27 +00:00
|
|
|
import FilesOverlay from '$lib/components/chat/MessageInput/FilesOverlay.svelte';
|
2025-12-10 05:53:41 +00:00
|
|
|
import DropdownOptions from '$lib/components/common/DropdownOptions.svelte';
|
|
|
|
|
import Pagination from '$lib/components/common/Pagination.svelte';
|
2024-10-20 07:36:43 +00:00
|
|
|
|
2024-10-03 03:42:10 +00:00
|
|
|
let largeScreen = true;
|
|
|
|
|
|
2024-10-20 07:36:43 +00:00
|
|
|
let pane;
|
|
|
|
|
let showSidepanel = true;
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
let showAddTextContentModal = false;
|
|
|
|
|
let showSyncConfirmModal = false;
|
|
|
|
|
let showAccessControlModal = false;
|
|
|
|
|
|
|
|
|
|
let minSize = 0;
|
2024-10-03 03:42:10 +00:00
|
|
|
type Knowledge = {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
data: {
|
|
|
|
|
file_ids: string[];
|
|
|
|
|
};
|
|
|
|
|
files: any[];
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-02 05:45:04 +00:00
|
|
|
let id = null;
|
2024-10-03 03:42:10 +00:00
|
|
|
let knowledge: Knowledge | null = null;
|
2025-12-10 05:55:31 +00:00
|
|
|
let knowledgeId = null;
|
2024-10-02 14:35:43 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
let selectedFileId = null;
|
|
|
|
|
let selectedFile = null;
|
|
|
|
|
let selectedFileContent = '';
|
2024-10-05 02:38:24 +00:00
|
|
|
|
2024-10-04 06:24:44 +00:00
|
|
|
let inputFiles = null;
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
let query = '';
|
|
|
|
|
let viewOption = null;
|
|
|
|
|
let sortKey = null;
|
|
|
|
|
let direction = null;
|
|
|
|
|
|
|
|
|
|
let currentPage = 1;
|
|
|
|
|
let fileItems = null;
|
|
|
|
|
let fileItemsTotal = null;
|
|
|
|
|
|
|
|
|
|
const reset = () => {
|
|
|
|
|
currentPage = 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const init = async () => {
|
|
|
|
|
reset();
|
|
|
|
|
await getItemsPage();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$: if (
|
2025-12-10 05:55:31 +00:00
|
|
|
knowledgeId !== null &&
|
2025-12-10 05:53:41 +00:00
|
|
|
query !== undefined &&
|
|
|
|
|
viewOption !== undefined &&
|
|
|
|
|
sortKey !== undefined &&
|
|
|
|
|
direction !== undefined &&
|
|
|
|
|
currentPage !== undefined
|
|
|
|
|
) {
|
|
|
|
|
getItemsPage();
|
2024-10-04 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
$: if (
|
|
|
|
|
query !== undefined &&
|
|
|
|
|
viewOption !== undefined &&
|
|
|
|
|
sortKey !== undefined &&
|
|
|
|
|
direction !== undefined
|
|
|
|
|
) {
|
|
|
|
|
reset();
|
2024-10-04 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
const getItemsPage = async () => {
|
2025-12-10 05:55:31 +00:00
|
|
|
if (knowledgeId === null) return;
|
2024-10-03 03:42:10 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
fileItems = null;
|
|
|
|
|
fileItemsTotal = null;
|
2024-10-03 03:42:10 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
if (sortKey === null) {
|
|
|
|
|
direction = null;
|
2024-10-04 04:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
const res = await searchKnowledgeFilesById(
|
|
|
|
|
localStorage.token,
|
|
|
|
|
knowledge.id,
|
|
|
|
|
query,
|
|
|
|
|
viewOption,
|
|
|
|
|
sortKey,
|
|
|
|
|
direction,
|
|
|
|
|
currentPage
|
|
|
|
|
).catch(() => {
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
fileItems = res.items;
|
|
|
|
|
fileItemsTotal = res.total;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fileSelectHandler = async (file) => {
|
|
|
|
|
try {
|
|
|
|
|
selectedFile = file;
|
|
|
|
|
selectedFileContent = selectedFile?.data?.content || '';
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast.error($i18n.t('Failed to load file content.'));
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-10-02 05:45:04 +00:00
|
|
|
|
2024-10-04 06:24:44 +00:00
|
|
|
const createFileFromText = (name, content) => {
|
|
|
|
|
const blob = new Blob([content], { type: 'text/plain' });
|
2024-10-20 07:42:45 +00:00
|
|
|
const file = blobToFile(blob, `${name}.txt`);
|
2024-10-04 06:24:44 +00:00
|
|
|
|
|
|
|
|
console.log(file);
|
|
|
|
|
return file;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-03 04:14:58 +00:00
|
|
|
const uploadFileHandler = async (file) => {
|
|
|
|
|
console.log(file);
|
|
|
|
|
|
2024-10-07 21:04:06 +00:00
|
|
|
const tempItemId = uuidv4();
|
2024-10-05 17:18:43 +00:00
|
|
|
const fileItem = {
|
|
|
|
|
type: 'file',
|
|
|
|
|
file: '',
|
|
|
|
|
id: null,
|
|
|
|
|
url: '',
|
|
|
|
|
name: file.name,
|
|
|
|
|
size: file.size,
|
|
|
|
|
status: 'uploading',
|
2024-10-07 21:04:06 +00:00
|
|
|
error: '',
|
|
|
|
|
itemId: tempItemId
|
2024-10-05 17:18:43 +00:00
|
|
|
};
|
|
|
|
|
|
2024-10-10 20:33:27 +00:00
|
|
|
if (fileItem.size == 0) {
|
2024-10-21 03:43:10 +00:00
|
|
|
toast.error($i18n.t('You cannot upload an empty file.'));
|
2024-10-10 20:33:27 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 15:36:41 +00:00
|
|
|
if (
|
|
|
|
|
($config?.file?.max_size ?? null) !== null &&
|
|
|
|
|
file.size > ($config?.file?.max_size ?? 0) * 1024 * 1024
|
|
|
|
|
) {
|
|
|
|
|
console.log('File exceeds max size limit:', {
|
|
|
|
|
fileSize: file.size,
|
|
|
|
|
maxSize: ($config?.file?.max_size ?? 0) * 1024 * 1024
|
|
|
|
|
});
|
|
|
|
|
toast.error(
|
|
|
|
|
$i18n.t(`File size should not exceed {{maxSize}} MB.`, {
|
|
|
|
|
maxSize: $config?.file?.max_size
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
fileItems = [...(fileItems ?? []), fileItem];
|
2024-10-03 04:14:58 +00:00
|
|
|
try {
|
2025-12-10 20:48:27 +00:00
|
|
|
let metadata = {
|
|
|
|
|
knowledge_id: knowledge.id,
|
|
|
|
|
// If the file is an audio file, provide the language for STT.
|
|
|
|
|
...((file.type.startsWith('audio/') || file.type.startsWith('video/')) &&
|
2025-05-23 20:36:30 +00:00
|
|
|
$settings?.audio?.stt?.language
|
2025-12-10 20:48:27 +00:00
|
|
|
? {
|
|
|
|
|
language: $settings?.audio?.stt?.language
|
|
|
|
|
}
|
|
|
|
|
: {})
|
|
|
|
|
};
|
2025-05-23 20:36:30 +00:00
|
|
|
|
|
|
|
|
const uploadedFile = await uploadFile(localStorage.token, file, metadata).catch((e) => {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-07 21:04:06 +00:00
|
|
|
return null;
|
2024-10-03 04:14:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (uploadedFile) {
|
2024-10-04 04:10:33 +00:00
|
|
|
console.log(uploadedFile);
|
2025-12-10 05:53:41 +00:00
|
|
|
fileItems = fileItems.map((item) => {
|
2024-10-07 21:04:06 +00:00
|
|
|
if (item.itemId === tempItemId) {
|
|
|
|
|
item.id = uploadedFile.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove temporary item id
|
|
|
|
|
delete item.itemId;
|
|
|
|
|
return item;
|
|
|
|
|
});
|
2025-10-28 07:34:53 +00:00
|
|
|
|
|
|
|
|
if (uploadedFile.error) {
|
|
|
|
|
console.warn('File upload warning:', uploadedFile.error);
|
|
|
|
|
toast.warning(uploadedFile.error);
|
2025-12-10 05:53:41 +00:00
|
|
|
fileItems = fileItems.filter((file) => file.id !== uploadedFile.id);
|
2025-10-28 07:34:53 +00:00
|
|
|
} else {
|
|
|
|
|
await addFileHandler(uploadedFile.id);
|
|
|
|
|
}
|
2024-10-03 04:14:58 +00:00
|
|
|
} else {
|
|
|
|
|
toast.error($i18n.t('Failed to upload file.'));
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-03 04:14:58 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-05 01:22:55 +00:00
|
|
|
const uploadDirectoryHandler = async () => {
|
2024-10-05 01:54:40 +00:00
|
|
|
// Check if File System Access API is supported
|
|
|
|
|
const isFileSystemAccessSupported = 'showDirectoryPicker' in window;
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
try {
|
|
|
|
|
if (isFileSystemAccessSupported) {
|
|
|
|
|
// Modern browsers (Chrome, Edge) implementation
|
|
|
|
|
await handleModernBrowserUpload();
|
|
|
|
|
} else {
|
|
|
|
|
// Firefox fallback
|
|
|
|
|
await handleFirefoxUpload();
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleUploadError(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-10-05 01:44:57 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Helper function to check if a path contains hidden folders
|
|
|
|
|
const hasHiddenFolder = (path) => {
|
|
|
|
|
return path.split('/').some((part) => part.startsWith('.'));
|
|
|
|
|
};
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Modern browsers implementation using File System Access API
|
|
|
|
|
const handleModernBrowserUpload = async () => {
|
|
|
|
|
const dirHandle = await window.showDirectoryPicker();
|
|
|
|
|
let totalFiles = 0;
|
|
|
|
|
let uploadedFiles = 0;
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Function to update the UI with the progress
|
|
|
|
|
const updateProgress = () => {
|
|
|
|
|
const percentage = (uploadedFiles / totalFiles) * 100;
|
2025-08-19 20:33:46 +00:00
|
|
|
toast.info(
|
|
|
|
|
$i18n.t('Upload Progress: {{uploadedFiles}}/{{totalFiles}} ({{percentage}}%)', {
|
|
|
|
|
uploadedFiles: uploadedFiles,
|
|
|
|
|
totalFiles: totalFiles,
|
|
|
|
|
percentage: percentage.toFixed(2)
|
|
|
|
|
})
|
|
|
|
|
);
|
2024-10-05 01:54:40 +00:00
|
|
|
};
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Recursive function to count all files excluding hidden ones
|
|
|
|
|
async function countFiles(dirHandle) {
|
|
|
|
|
for await (const entry of dirHandle.values()) {
|
|
|
|
|
// Skip hidden files and directories
|
|
|
|
|
if (entry.name.startsWith('.')) continue;
|
|
|
|
|
|
|
|
|
|
if (entry.kind === 'file') {
|
|
|
|
|
totalFiles++;
|
|
|
|
|
} else if (entry.kind === 'directory') {
|
|
|
|
|
// Only process non-hidden directories
|
|
|
|
|
if (!entry.name.startsWith('.')) {
|
2024-10-05 01:22:55 +00:00
|
|
|
await countFiles(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-05 01:54:40 +00:00
|
|
|
}
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Recursive function to process directories excluding hidden files and folders
|
|
|
|
|
async function processDirectory(dirHandle, path = '') {
|
|
|
|
|
for await (const entry of dirHandle.values()) {
|
|
|
|
|
// Skip hidden files and directories
|
|
|
|
|
if (entry.name.startsWith('.')) continue;
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
const entryPath = path ? `${path}/${entry.name}` : entry.name;
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
// Skip if the path contains any hidden folders
|
|
|
|
|
if (hasHiddenFolder(entryPath)) continue;
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
if (entry.kind === 'file') {
|
|
|
|
|
const file = await entry.getFile();
|
|
|
|
|
const fileWithPath = new File([file], entryPath, { type: file.type });
|
|
|
|
|
|
|
|
|
|
await uploadFileHandler(fileWithPath);
|
|
|
|
|
uploadedFiles++;
|
|
|
|
|
updateProgress();
|
|
|
|
|
} else if (entry.kind === 'directory') {
|
|
|
|
|
// Only process non-hidden directories
|
|
|
|
|
if (!entry.name.startsWith('.')) {
|
2024-10-05 01:22:55 +00:00
|
|
|
await processDirectory(entry, entryPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-05 01:54:40 +00:00
|
|
|
}
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
await countFiles(dirHandle);
|
|
|
|
|
updateProgress();
|
2024-10-05 01:22:55 +00:00
|
|
|
|
2024-10-05 01:54:40 +00:00
|
|
|
if (totalFiles > 0) {
|
|
|
|
|
await processDirectory(dirHandle);
|
|
|
|
|
} else {
|
|
|
|
|
console.log('No files to upload.');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Firefox fallback implementation using traditional file input
|
|
|
|
|
const handleFirefoxUpload = async () => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// Create hidden file input
|
|
|
|
|
const input = document.createElement('input');
|
|
|
|
|
input.type = 'file';
|
|
|
|
|
input.webkitdirectory = true;
|
|
|
|
|
input.directory = true;
|
|
|
|
|
input.multiple = true;
|
|
|
|
|
input.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
// Add input to DOM temporarily
|
|
|
|
|
document.body.appendChild(input);
|
|
|
|
|
|
|
|
|
|
input.onchange = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const files = Array.from(input.files)
|
|
|
|
|
// Filter out files from hidden folders
|
|
|
|
|
.filter((file) => !hasHiddenFolder(file.webkitRelativePath));
|
|
|
|
|
|
|
|
|
|
let totalFiles = files.length;
|
|
|
|
|
let uploadedFiles = 0;
|
|
|
|
|
|
|
|
|
|
// Function to update the UI with the progress
|
|
|
|
|
const updateProgress = () => {
|
|
|
|
|
const percentage = (uploadedFiles / totalFiles) * 100;
|
|
|
|
|
toast.info(
|
2025-08-19 20:33:46 +00:00
|
|
|
$i18n.t('Upload Progress: {{uploadedFiles}}/{{totalFiles}} ({{percentage}}%)', {
|
|
|
|
|
uploadedFiles: uploadedFiles,
|
|
|
|
|
totalFiles: totalFiles,
|
|
|
|
|
percentage: percentage.toFixed(2)
|
|
|
|
|
})
|
2024-10-05 01:54:40 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateProgress();
|
|
|
|
|
|
|
|
|
|
// Process all files
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
// Skip hidden files (additional check)
|
|
|
|
|
if (!file.name.startsWith('.')) {
|
|
|
|
|
const relativePath = file.webkitRelativePath || file.name;
|
|
|
|
|
const fileWithPath = new File([file], relativePath, { type: file.type });
|
|
|
|
|
|
|
|
|
|
await uploadFileHandler(fileWithPath);
|
|
|
|
|
uploadedFiles++;
|
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
document.body.removeChild(input);
|
|
|
|
|
resolve();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
input.onerror = (error) => {
|
|
|
|
|
document.body.removeChild(input);
|
|
|
|
|
reject(error);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Trigger file picker
|
|
|
|
|
input.click();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Error handler
|
|
|
|
|
const handleUploadError = (error) => {
|
|
|
|
|
if (error.name === 'AbortError') {
|
2025-08-14 00:15:16 +00:00
|
|
|
toast.info($i18n.t('Directory selection was cancelled'));
|
2024-10-05 01:54:40 +00:00
|
|
|
} else {
|
2025-08-14 00:15:16 +00:00
|
|
|
toast.error($i18n.t('Error accessing directory'));
|
2024-10-05 01:54:40 +00:00
|
|
|
console.error('Directory access error:', error);
|
2024-10-05 01:22:55 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper function to maintain file paths within zip
|
2024-10-05 01:44:57 +00:00
|
|
|
const syncDirectoryHandler = async () => {
|
2024-10-06 02:53:19 +00:00
|
|
|
if ((knowledge?.files ?? []).length > 0) {
|
|
|
|
|
const res = await resetKnowledgeById(localStorage.token, id).catch((e) => {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-06 02:53:19 +00:00
|
|
|
});
|
2024-10-05 01:44:57 +00:00
|
|
|
|
2024-10-06 02:53:19 +00:00
|
|
|
if (res) {
|
|
|
|
|
knowledge = res;
|
|
|
|
|
toast.success($i18n.t('Knowledge reset successfully.'));
|
2024-10-05 01:44:57 +00:00
|
|
|
|
2024-10-06 02:53:19 +00:00
|
|
|
// Upload directory
|
|
|
|
|
uploadDirectoryHandler();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-05 01:44:57 +00:00
|
|
|
uploadDirectoryHandler();
|
|
|
|
|
}
|
2024-10-05 01:22:55 +00:00
|
|
|
};
|
|
|
|
|
|
2024-10-04 05:22:22 +00:00
|
|
|
const addFileHandler = async (fileId) => {
|
2025-12-10 20:48:27 +00:00
|
|
|
const res = await addFileToKnowledgeById(localStorage.token, id, fileId).catch((e) => {
|
|
|
|
|
toast.error(`${e}`);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
2024-10-04 04:10:33 +00:00
|
|
|
|
2025-12-10 20:48:27 +00:00
|
|
|
if (res) {
|
2024-10-04 05:22:22 +00:00
|
|
|
toast.success($i18n.t('File added successfully.'));
|
2025-12-10 20:48:27 +00:00
|
|
|
init();
|
2024-10-07 21:04:06 +00:00
|
|
|
} else {
|
|
|
|
|
toast.error($i18n.t('Failed to add file.'));
|
2025-12-10 05:53:41 +00:00
|
|
|
fileItems = fileItems.filter((file) => file.id !== fileId);
|
2024-10-04 05:22:22 +00:00
|
|
|
}
|
|
|
|
|
};
|
2024-10-04 04:10:33 +00:00
|
|
|
|
2024-10-04 05:22:22 +00:00
|
|
|
const deleteFileHandler = async (fileId) => {
|
2025-01-13 17:21:00 +00:00
|
|
|
try {
|
|
|
|
|
console.log('Starting file deletion process for:', fileId);
|
2024-10-04 04:10:33 +00:00
|
|
|
|
2025-01-13 17:21:00 +00:00
|
|
|
// Remove from knowledge base only
|
2025-12-10 20:48:27 +00:00
|
|
|
const res = await removeFileFromKnowledgeById(localStorage.token, id, fileId);
|
|
|
|
|
console.log('Knowledge base updated:', res);
|
2025-01-13 17:21:00 +00:00
|
|
|
|
2025-12-10 20:48:27 +00:00
|
|
|
if (res) {
|
2025-01-13 17:21:00 +00:00
|
|
|
toast.success($i18n.t('File removed successfully.'));
|
2025-12-10 20:48:27 +00:00
|
|
|
await init();
|
2025-01-13 17:21:00 +00:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Error in deleteFileHandler:', e);
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-04 04:10:33 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
let debounceTimeout = null;
|
|
|
|
|
let mediaQuery;
|
|
|
|
|
|
|
|
|
|
let dragged = false;
|
|
|
|
|
let isSaving = false;
|
|
|
|
|
|
2024-10-04 07:46:32 +00:00
|
|
|
const updateFileContentHandler = async () => {
|
2025-09-02 11:53:04 +00:00
|
|
|
if (isSaving) {
|
|
|
|
|
console.log('Save operation already in progress, skipping...');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-10 05:53:41 +00:00
|
|
|
|
2025-09-02 11:53:04 +00:00
|
|
|
isSaving = true;
|
2025-12-10 05:53:41 +00:00
|
|
|
|
2025-09-02 11:53:04 +00:00
|
|
|
try {
|
2025-12-10 05:53:41 +00:00
|
|
|
const res = await updateFileDataContentById(
|
2025-09-02 11:53:04 +00:00
|
|
|
localStorage.token,
|
2025-12-10 05:53:41 +00:00
|
|
|
selectedFile.id,
|
|
|
|
|
selectedFileContent
|
2025-09-02 11:53:04 +00:00
|
|
|
).catch((e) => {
|
|
|
|
|
toast.error(`${e}`);
|
2025-12-10 05:53:41 +00:00
|
|
|
return null;
|
2025-09-02 11:53:04 +00:00
|
|
|
});
|
2025-12-10 05:53:41 +00:00
|
|
|
|
|
|
|
|
if (res) {
|
2025-09-02 11:53:04 +00:00
|
|
|
toast.success($i18n.t('File content updated successfully.'));
|
2025-12-10 05:53:41 +00:00
|
|
|
|
|
|
|
|
selectedFileId = null;
|
|
|
|
|
selectedFile = null;
|
|
|
|
|
selectedFileContent = '';
|
|
|
|
|
|
|
|
|
|
await init();
|
2025-09-02 11:53:04 +00:00
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
isSaving = false;
|
2024-10-04 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-04 04:10:33 +00:00
|
|
|
const changeDebounceHandler = () => {
|
|
|
|
|
console.log('debounce');
|
|
|
|
|
if (debounceTimeout) {
|
|
|
|
|
clearTimeout(debounceTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debounceTimeout = setTimeout(async () => {
|
2024-10-04 23:58:45 +00:00
|
|
|
if (knowledge.name.trim() === '' || knowledge.description.trim() === '') {
|
|
|
|
|
toast.error($i18n.t('Please fill in all fields.'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 04:10:33 +00:00
|
|
|
const res = await updateKnowledgeById(localStorage.token, id, {
|
2024-11-18 01:37:26 +00:00
|
|
|
...knowledge,
|
2024-10-04 04:10:33 +00:00
|
|
|
name: knowledge.name,
|
2024-11-17 04:47:45 +00:00
|
|
|
description: knowledge.description,
|
|
|
|
|
access_control: knowledge.access_control
|
2024-10-04 04:10:33 +00:00
|
|
|
}).catch((e) => {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-04 04:10:33 +00:00
|
|
|
});
|
2024-10-03 03:42:10 +00:00
|
|
|
|
2024-10-04 04:10:33 +00:00
|
|
|
if (res) {
|
|
|
|
|
toast.success($i18n.t('Knowledge updated successfully'));
|
2024-11-17 00:51:55 +00:00
|
|
|
_knowledge.set(await getKnowledgeBases(localStorage.token));
|
2024-10-04 04:10:33 +00:00
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleMediaQuery = async (e) => {
|
|
|
|
|
if (e.matches) {
|
|
|
|
|
largeScreen = true;
|
|
|
|
|
} else {
|
|
|
|
|
largeScreen = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDragOver = (e) => {
|
|
|
|
|
e.preventDefault();
|
2024-12-01 06:29:53 +00:00
|
|
|
|
|
|
|
|
// Check if a file is being draggedOver.
|
|
|
|
|
if (e.dataTransfer?.types?.includes('Files')) {
|
|
|
|
|
dragged = true;
|
|
|
|
|
} else {
|
|
|
|
|
dragged = false;
|
|
|
|
|
}
|
2024-10-04 04:10:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDragLeave = () => {
|
|
|
|
|
dragged = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDrop = async (e) => {
|
|
|
|
|
e.preventDefault();
|
2024-10-05 17:18:43 +00:00
|
|
|
dragged = false;
|
2024-10-04 04:10:33 +00:00
|
|
|
|
2025-11-20 21:26:36 +00:00
|
|
|
const handleUploadingFileFolder = (items) => {
|
2025-11-20 23:32:34 +00:00
|
|
|
for (const item of items) {
|
|
|
|
|
if (item.isFile) {
|
2025-11-20 21:26:36 +00:00
|
|
|
item.file((file) => {
|
|
|
|
|
uploadFileHandler(file);
|
2025-11-20 23:32:34 +00:00
|
|
|
});
|
2025-11-20 21:26:36 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2025-11-20 23:32:34 +00:00
|
|
|
|
2025-11-20 21:26:36 +00:00
|
|
|
// Not sure why you have to call webkitGetAsEntry and isDirectory seperate, but it won't work if you try item.webkitGetAsEntry().isDirectory
|
|
|
|
|
const wkentry = item.webkitGetAsEntry();
|
|
|
|
|
const isDirectory = wkentry.isDirectory;
|
2025-11-20 23:32:34 +00:00
|
|
|
if (isDirectory) {
|
2025-11-20 21:26:36 +00:00
|
|
|
// Read the directory
|
2025-11-20 23:32:34 +00:00
|
|
|
wkentry.createReader().readEntries(
|
|
|
|
|
(entries) => {
|
|
|
|
|
handleUploadingFileFolder(entries);
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
console.error('Error reading directory entries:', error);
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-11-20 21:26:36 +00:00
|
|
|
} else {
|
|
|
|
|
toast.info($i18n.t('Uploading file...'));
|
|
|
|
|
uploadFileHandler(item.getAsFile());
|
|
|
|
|
toast.success($i18n.t('File uploaded!'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-20 23:32:34 +00:00
|
|
|
};
|
2025-11-20 21:26:36 +00:00
|
|
|
|
2024-12-01 06:29:53 +00:00
|
|
|
if (e.dataTransfer?.types?.includes('Files')) {
|
|
|
|
|
if (e.dataTransfer?.files) {
|
2025-11-20 21:26:36 +00:00
|
|
|
const inputItems = e.dataTransfer?.items;
|
2024-10-04 04:10:33 +00:00
|
|
|
|
2025-11-20 21:26:36 +00:00
|
|
|
if (inputItems && inputItems.length > 0) {
|
2025-11-20 23:32:34 +00:00
|
|
|
handleUploadingFileFolder(inputItems);
|
2024-12-01 06:29:53 +00:00
|
|
|
} else {
|
|
|
|
|
toast.error($i18n.t(`File not found.`));
|
2024-10-04 04:10:33 +00:00
|
|
|
}
|
2024-10-03 03:42:10 +00:00
|
|
|
}
|
2024-10-04 04:10:33 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
// listen to resize 1024px
|
|
|
|
|
mediaQuery = window.matchMedia('(min-width: 1024px)');
|
2024-10-03 03:42:10 +00:00
|
|
|
|
|
|
|
|
mediaQuery.addEventListener('change', handleMediaQuery);
|
|
|
|
|
handleMediaQuery(mediaQuery);
|
|
|
|
|
|
2024-10-20 07:36:43 +00:00
|
|
|
// Select the container element you want to observe
|
|
|
|
|
const container = document.getElementById('collection-container');
|
|
|
|
|
|
|
|
|
|
// initialize the minSize based on the container width
|
|
|
|
|
minSize = !largeScreen ? 100 : Math.floor((300 / container.clientWidth) * 100);
|
|
|
|
|
|
|
|
|
|
// Create a new ResizeObserver instance
|
|
|
|
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
|
|
|
for (let entry of entries) {
|
|
|
|
|
const width = entry.contentRect.width;
|
|
|
|
|
// calculate the percentage of 300
|
|
|
|
|
const percentage = (300 / width) * 100;
|
|
|
|
|
// set the minSize to the percentage, must be an integer
|
|
|
|
|
minSize = !largeScreen ? 100 : Math.floor(percentage);
|
2024-10-20 07:47:43 +00:00
|
|
|
|
|
|
|
|
if (showSidepanel) {
|
|
|
|
|
if (pane && pane.isExpanded() && pane.getSize() < minSize) {
|
|
|
|
|
pane.resize(minSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-20 07:36:43 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Start observing the container's size changes
|
|
|
|
|
resizeObserver.observe(container);
|
|
|
|
|
|
|
|
|
|
if (pane) {
|
|
|
|
|
pane.expand();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 05:45:04 +00:00
|
|
|
id = $page.params.id;
|
|
|
|
|
const res = await getKnowledgeById(localStorage.token, id).catch((e) => {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-03 04:14:58 +00:00
|
|
|
return null;
|
2024-10-02 05:45:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
knowledge = res;
|
2025-12-10 05:55:31 +00:00
|
|
|
knowledgeId = knowledge?.id;
|
2024-10-02 05:45:04 +00:00
|
|
|
} else {
|
|
|
|
|
goto('/workspace/knowledge');
|
|
|
|
|
}
|
2024-10-03 03:42:10 +00:00
|
|
|
|
|
|
|
|
const dropZone = document.querySelector('body');
|
|
|
|
|
dropZone?.addEventListener('dragover', onDragOver);
|
|
|
|
|
dropZone?.addEventListener('drop', onDrop);
|
|
|
|
|
dropZone?.addEventListener('dragleave', onDragLeave);
|
2024-10-04 04:10:33 +00:00
|
|
|
});
|
2024-10-03 03:42:10 +00:00
|
|
|
|
2024-10-04 04:10:33 +00:00
|
|
|
onDestroy(() => {
|
|
|
|
|
mediaQuery?.removeEventListener('change', handleMediaQuery);
|
|
|
|
|
const dropZone = document.querySelector('body');
|
|
|
|
|
dropZone?.removeEventListener('dragover', onDragOver);
|
|
|
|
|
dropZone?.removeEventListener('drop', onDrop);
|
|
|
|
|
dropZone?.removeEventListener('dragleave', onDragLeave);
|
2024-10-02 05:45:04 +00:00
|
|
|
});
|
2025-04-11 22:27:25 +00:00
|
|
|
|
|
|
|
|
const decodeString = (str: string) => {
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(str);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-10-02 05:45:04 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-09-14 06:42:27 +00:00
|
|
|
<FilesOverlay show={dragged} />
|
2024-10-05 02:38:24 +00:00
|
|
|
<SyncConfirmDialog
|
|
|
|
|
bind:show={showSyncConfirmModal}
|
|
|
|
|
message={$i18n.t(
|
|
|
|
|
'This will reset the knowledge base and sync all files. Do you wish to continue?'
|
|
|
|
|
)}
|
|
|
|
|
on:confirm={() => {
|
|
|
|
|
syncDirectoryHandler();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
2024-10-04 06:24:44 +00:00
|
|
|
<AddTextContentModal
|
|
|
|
|
bind:show={showAddTextContentModal}
|
|
|
|
|
on:submit={(e) => {
|
|
|
|
|
const file = createFileFromText(e.detail.name, e.detail.content);
|
|
|
|
|
uploadFileHandler(file);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
id="files-input"
|
|
|
|
|
bind:files={inputFiles}
|
|
|
|
|
type="file"
|
|
|
|
|
multiple
|
|
|
|
|
hidden
|
2024-10-07 21:05:45 +00:00
|
|
|
on:change={async () => {
|
2024-10-04 06:24:44 +00:00
|
|
|
if (inputFiles && inputFiles.length > 0) {
|
|
|
|
|
for (const file of inputFiles) {
|
2024-10-07 21:05:45 +00:00
|
|
|
await uploadFileHandler(file);
|
2024-10-04 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inputFiles = null;
|
|
|
|
|
const fileInputElement = document.getElementById('files-input');
|
|
|
|
|
|
|
|
|
|
if (fileInputElement) {
|
|
|
|
|
fileInputElement.value = '';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toast.error($i18n.t(`File not found.`));
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
<div class="flex flex-col w-full h-full min-h-full" id="collection-container">
|
2024-10-18 21:55:39 +00:00
|
|
|
{#if id && knowledge}
|
2024-11-17 04:47:45 +00:00
|
|
|
<AccessControlModal
|
|
|
|
|
bind:show={showAccessControlModal}
|
|
|
|
|
bind:accessControl={knowledge.access_control}
|
2025-11-20 23:32:34 +00:00
|
|
|
share={$user?.permissions?.sharing?.knowledge || $user?.role === 'admin'}
|
2025-12-10 05:53:41 +00:00
|
|
|
sharePublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
2024-11-17 04:47:45 +00:00
|
|
|
onChange={() => {
|
|
|
|
|
changeDebounceHandler();
|
|
|
|
|
}}
|
2025-01-21 07:20:47 +00:00
|
|
|
accessRoles={['read', 'write']}
|
2024-11-17 04:47:45 +00:00
|
|
|
/>
|
2025-12-10 05:53:41 +00:00
|
|
|
<div class="w-full px-2">
|
2024-11-17 04:47:45 +00:00
|
|
|
<div class=" flex w-full">
|
|
|
|
|
<div class="flex-1">
|
2025-12-10 05:53:41 +00:00
|
|
|
<div class="flex items-center justify-between w-full">
|
|
|
|
|
<div class="w-full flex justify-between items-center">
|
2024-11-17 04:47:45 +00:00
|
|
|
<input
|
|
|
|
|
type="text"
|
2025-12-10 05:53:41 +00:00
|
|
|
class="text-left w-full font-medium text-lg font-primary bg-transparent outline-hidden flex-1"
|
2024-11-17 04:47:45 +00:00
|
|
|
bind:value={knowledge.name}
|
2025-08-14 00:15:16 +00:00
|
|
|
placeholder={$i18n.t('Knowledge Name')}
|
2024-11-17 04:47:45 +00:00
|
|
|
on:input={() => {
|
|
|
|
|
changeDebounceHandler();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-12-10 05:53:41 +00:00
|
|
|
|
|
|
|
|
<div class="shrink-0 mr-2.5">
|
|
|
|
|
{#if (knowledge?.files ?? []).length}
|
|
|
|
|
<div class="text-xs text-gray-500">
|
|
|
|
|
{$i18n.t('{{count}} files', {
|
|
|
|
|
count: (knowledge?.files ?? []).length
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-11-17 04:47:45 +00:00
|
|
|
</div>
|
|
|
|
|
|
2025-02-16 03:27:25 +00:00
|
|
|
<div class="self-center shrink-0">
|
2024-11-17 04:47:45 +00:00
|
|
|
<button
|
2024-11-17 10:58:24 +00:00
|
|
|
class="bg-gray-50 hover:bg-gray-100 text-black dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-white transition px-2 py-1 rounded-full flex gap-1 items-center"
|
2024-11-17 04:47:45 +00:00
|
|
|
type="button"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
showAccessControlModal = true;
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-17 05:00:20 +00:00
|
|
|
<LockClosed strokeWidth="2.5" className="size-3.5" />
|
2024-11-17 04:47:45 +00:00
|
|
|
|
2025-02-16 03:27:25 +00:00
|
|
|
<div class="text-sm font-medium shrink-0">
|
2024-11-18 00:13:59 +00:00
|
|
|
{$i18n.t('Access')}
|
2024-11-17 04:47:45 +00:00
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
<div class="flex w-full">
|
2024-11-17 04:47:45 +00:00
|
|
|
<input
|
|
|
|
|
type="text"
|
2025-02-16 03:27:25 +00:00
|
|
|
class="text-left text-xs w-full text-gray-500 bg-transparent outline-hidden"
|
2024-11-17 04:47:45 +00:00
|
|
|
bind:value={knowledge.description}
|
2025-08-14 00:15:16 +00:00
|
|
|
placeholder={$i18n.t('Knowledge Description')}
|
2024-11-17 04:47:45 +00:00
|
|
|
on:input={() => {
|
|
|
|
|
changeDebounceHandler();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
<div
|
|
|
|
|
class="mt-2 mb-2.5 py-2 -mx-0 bg-white dark:bg-gray-900 rounded-3xl border border-gray-100/30 dark:border-gray-850/30 flex-1"
|
|
|
|
|
>
|
|
|
|
|
<div class="px-3.5 flex flex-1 items-center w-full space-x-2 py-0.5 pb-2">
|
|
|
|
|
<div class="flex flex-1 items-center">
|
|
|
|
|
<div class=" self-center ml-1 mr-3">
|
|
|
|
|
<Search className="size-3.5" />
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
|
|
|
|
class=" w-full text-sm pr-4 py-1 rounded-r-xl outline-hidden bg-transparent"
|
|
|
|
|
bind:value={query}
|
|
|
|
|
placeholder={`${$i18n.t('Search Collection')}`}
|
|
|
|
|
on:focus={() => {
|
|
|
|
|
selectedFileId = null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<AddContentMenu
|
|
|
|
|
on:upload={(e) => {
|
|
|
|
|
if (e.detail.type === 'directory') {
|
|
|
|
|
uploadDirectoryHandler();
|
|
|
|
|
} else if (e.detail.type === 'text') {
|
|
|
|
|
showAddTextContentModal = true;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('files-input').click();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
on:sync={(e) => {
|
|
|
|
|
showSyncConfirmModal = true;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-10-04 06:41:17 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
<div class="px-3 flex justify-between">
|
|
|
|
|
<div
|
|
|
|
|
class="flex w-full bg-transparent overflow-x-auto scrollbar-none"
|
|
|
|
|
on:wheel={(e) => {
|
|
|
|
|
if (e.deltaY !== 0) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.currentTarget.scrollLeft += e.deltaY;
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
class="flex gap-3 w-fit text-center text-sm rounded-full bg-transparent px-0.5 whitespace-nowrap"
|
|
|
|
|
>
|
|
|
|
|
<DropdownOptions
|
|
|
|
|
align="start"
|
|
|
|
|
className="flex w-full items-center gap-2 truncate px-3 py-1.5 text-sm bg-gray-50 dark:bg-gray-850 rounded-xl placeholder-gray-400 outline-hidden focus:outline-hidden"
|
|
|
|
|
bind:value={viewOption}
|
|
|
|
|
items={[
|
|
|
|
|
{ value: null, label: $i18n.t('All') },
|
|
|
|
|
{ value: 'created', label: $i18n.t('Created by you') },
|
|
|
|
|
{ value: 'shared', label: $i18n.t('Shared with you') }
|
|
|
|
|
]}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
localStorage.workspaceViewOption = value;
|
|
|
|
|
} else {
|
|
|
|
|
delete localStorage.workspaceViewOption;
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-10-20 07:36:43 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
<DropdownOptions
|
|
|
|
|
align="start"
|
|
|
|
|
bind:value={sortKey}
|
|
|
|
|
placeholder={$i18n.t('Sort')}
|
|
|
|
|
items={[
|
|
|
|
|
{ value: 'name', label: $i18n.t('Name') },
|
|
|
|
|
{ value: 'created_at', label: $i18n.t('Created At') },
|
|
|
|
|
{ value: 'updated_at', label: $i18n.t('Updated At') }
|
|
|
|
|
]}
|
|
|
|
|
/>
|
2024-11-16 02:21:41 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
{#if sortKey}
|
|
|
|
|
<DropdownOptions
|
|
|
|
|
align="start"
|
|
|
|
|
bind:value={direction}
|
|
|
|
|
items={[
|
|
|
|
|
{ value: 'asc', label: $i18n.t('Asc') },
|
|
|
|
|
{ value: null, label: $i18n.t('Desc') }
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
2025-12-10 05:53:41 +00:00
|
|
|
</div>
|
2024-10-20 07:36:43 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
{#if fileItems !== null && fileItemsTotal !== null}
|
|
|
|
|
<div class="flex flex-row flex-1 gap-3 px-2.5 mt-2">
|
|
|
|
|
<div class="flex-1 flex">
|
|
|
|
|
<div class=" flex flex-col w-full space-x-2 rounded-lg h-full">
|
|
|
|
|
<div class="w-full h-full flex flex-col min-h-full">
|
|
|
|
|
{#if fileItems.length > 0}
|
|
|
|
|
<div class=" flex overflow-y-auto h-full w-full scrollbar-hidden text-xs">
|
|
|
|
|
<Files
|
|
|
|
|
files={fileItems}
|
|
|
|
|
{selectedFileId}
|
|
|
|
|
onClick={(fileId) => {
|
|
|
|
|
selectedFileId = fileId;
|
|
|
|
|
|
|
|
|
|
if (fileItems) {
|
|
|
|
|
const file = fileItems.find((file) => file.id === selectedFileId);
|
|
|
|
|
if (file) {
|
|
|
|
|
fileSelectHandler(file);
|
|
|
|
|
} else {
|
|
|
|
|
selectedFile = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onDelete={(fileId) => {
|
|
|
|
|
selectedFileId = null;
|
|
|
|
|
selectedFile = null;
|
2024-10-07 21:49:26 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
deleteFileHandler(fileId);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if fileItemsTotal > 30}
|
|
|
|
|
<Pagination bind:page={currentPage} count={fileItemsTotal} perPage={30} />
|
|
|
|
|
{/if}
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="my-3 flex flex-col justify-center text-center text-gray-500 text-xs">
|
|
|
|
|
<div>
|
|
|
|
|
{$i18n.t('No content found')}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
{#if selectedFileId !== null}
|
|
|
|
|
<Drawer
|
|
|
|
|
className="h-full"
|
|
|
|
|
show={selectedFileId !== null}
|
|
|
|
|
onClose={() => {
|
|
|
|
|
selectedFileId = null;
|
|
|
|
|
selectedFile = null;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class="flex flex-col justify-start h-full max-h-full">
|
|
|
|
|
<div class=" flex flex-col w-full h-full max-h-full">
|
|
|
|
|
<div class="shrink-0 flex items-center p-2">
|
|
|
|
|
<div class="mr-2">
|
|
|
|
|
<button
|
|
|
|
|
class="w-full text-left text-sm p-1.5 rounded-lg dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-gray-850"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
selectedFileId = null;
|
|
|
|
|
selectedFile = null;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<ChevronLeft strokeWidth="2.5" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=" flex-1 text-lg line-clamp-1">
|
|
|
|
|
{selectedFile?.meta?.name}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
class="flex self-center w-fit text-sm py-1 px-2.5 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed"
|
|
|
|
|
disabled={isSaving}
|
|
|
|
|
on:click={() => {
|
|
|
|
|
updateFileContentHandler();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{$i18n.t('Save')}
|
|
|
|
|
{#if isSaving}
|
|
|
|
|
<div class="ml-2 self-center">
|
|
|
|
|
<Spinner />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-11-30 23:44:04 +00:00
|
|
|
|
2025-12-10 05:53:41 +00:00
|
|
|
{#key selectedFile.id}
|
|
|
|
|
<textarea
|
|
|
|
|
class="w-full h-full text-sm outline-none resize-none px-3 py-2"
|
|
|
|
|
bind:value={selectedFileContent}
|
|
|
|
|
placeholder={$i18n.t('Add content here')}
|
|
|
|
|
/>
|
|
|
|
|
{/key}
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-12-10 05:53:41 +00:00
|
|
|
</Drawer>
|
|
|
|
|
{/if}
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
2025-12-10 05:53:41 +00:00
|
|
|
{:else}
|
|
|
|
|
<div class="my-10">
|
|
|
|
|
<Spinner className="size-4" />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-10-18 21:55:39 +00:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
2025-06-27 12:15:16 +00:00
|
|
|
<Spinner className="size-5" />
|
2024-10-18 21:55:39 +00:00
|
|
|
{/if}
|
2024-10-02 05:45:04 +00:00
|
|
|
</div>
|