Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

fix: oprimize and fix import system

Smaug6739cdabb02475e0
diff --git a/frontend/app/composables/useNodesTree.ts b/frontend/app/composables/useNodesTree.ts
index ff8c59ae..bd477af9 100644
--- a/frontend/app/composables/useNodesTree.ts
+++ b/frontend/app/composables/useNodesTree.ts
@@ -126,6 +126,7 @@ export function useNodesTree() {
rootFilter: node => {
if (node.role === 0) return true;
if (node.role === 1 && !nodesStore.getById(node.parent_id ?? '')) return true;
+ if (!nodesStore.getById(node.parent_id ?? '')) return true;
return false;
},
});
diff --git a/frontend/app/helpers/backups/Importer.ts b/frontend/app/helpers/backups/Importer.ts
index 1eb22e40..f73b1562 100644
--- a/frontend/app/helpers/backups/Importer.ts
+++ b/frontend/app/helpers/backups/Importer.ts
@@ -2,11 +2,22 @@ import compile from '~/helpers/markdown';
import { extractMetadataFromMarkdown } from '~/helpers/node';
import type { DB_Node } from '~/stores';
+export interface ImportJob {
+ status: 'pending' | 'in_progress' | 'completed' | 'failed';
+ toCreate: DB_Node[];
+ created: string[];
+ toUpdate: DB_Node[];
+ updated: string[];
+ failures: number;
+ error_message?: string;
+ options: ImportOptions;
+}
+
interface ImportOptions {
- extractFrontMatter: boolean;
- normalizeLineEndings: boolean;
- preserveTimestamps: boolean;
- defaultValues: {
+ extractFrontMatter?: boolean;
+ normalizeLineEndings?: boolean;
+ preserveTimestamps?: boolean;
+ defaultValues?: {
defaultParent?: string;
defaultDescription: string;
defaultTags: string;
@@ -15,7 +26,6 @@ interface ImportOptions {
defaultIcon: string;
defaultTheme: string;
};
- user_id: string;
}
interface NormalizedEntry<T = 'folder' | 'text_based' | 'resource'> {
@@ -24,7 +34,7 @@ interface NormalizedEntry<T = 'folder' | 'text_based' | 'resource'> {
file: File;
filename?: string;
children?: NormalizedEntry[];
- content: string | ArrayBuffer; // Restera vide pour les ressources binaires
+ content: string | ArrayBuffer;
}
export interface ResourceImportTask {
id: string;
@@ -59,8 +69,8 @@ export class Importer {
const path = file.webkitRelativePath; // ex: "A/B/C/D/file.txt"
const parts = path.split('/'); // ["A", "B", "C", "D", "file.txt"]
- // --- 1. RECONSTRUCTION DES DOSSIERS INTERMÉDIAIRES ---
- // On boucle sur tous les segments sauf le dernier (qui est le fichier lui-même)
+ // --- 1. REBUILDING INTERMEDIATE FOLDERS ---
+ // We iterate through the parts of the path, creating folder entries in normalized_files as needed.
let currentPath: string = '';
for (let i = 0; i < parts.length - 1; i++) {
@@ -68,38 +78,38 @@ export class Importer {
const previousPath = currentPath;
currentPath = currentPath ? `${currentPath}/${folderName}` : folderName;
- // On vérifie si ce niveau de dossier existe déjà dans l'arborescence globale
+ // We check if this level of folder already exists in the global tree
let folderEntry = this.normalized_files.find(e => e.id === currentPath);
- // Si on est au premier niveau ("A"), le parent est la racine (undefined),
- // sinon c'est le dossier précédent ("A/B" a pour parent "A")
+ // If we are at the first level ("A"), the parent is the root (undefined),
+ // otherwise it's the previous folder ("A/B" has "A" as parent)
if (!folderEntry) {
folderEntry = {
id: currentPath,
filetype: 'folder',
- file: file, // On associe le fichier courant à défaut d'avoir un objet File pour le dossier
+ file: file, // We use the current file as a placeholder for the folder entry
filename: folderName,
children: [],
content: '',
};
if (!previousPath) {
- // Dossier racine de l'import (ex: "A")
+ // Root folder of the import (ex: "A")
this.normalized_files.push(folderEntry);
} else {
- // Trouver le dossier parent direct dans la structure globale pour lui affecter son enfant
+ // Find the direct parent folder in the global structure to assign it as a child
const parentEntry = this.normalized_files.find(e => e.id === previousPath);
if (parentEntry && parentEntry.children) {
parentEntry.children.push(folderEntry);
} else {
- // Sécurité si le traitement n'est pas linéaire (théoriquement impossible ici)
+ // Security: If the parent folder doesn't exist (which shouldn't happen), we add the folder to the root of normalized_files
this.normalized_files.push(folderEntry);
}
}
}
}
- // --- 2. AJOUT DU FICHIER DANS SON DOSSIER PARENT FINAL ---
+ // --- 2. ADDING THE FILE TO ITS FINAL PARENT FOLDER ---
const finalParentPath = parts.slice(0, -1).join('/');
const isText = file.type.startsWith('text/') || file.name.endsWith('.md') || file.name.endsWith('.json');
const filetype: 'folder' | 'text_based' | 'resource' = isText ? 'text_based' : 'resource';
@@ -113,12 +123,12 @@ export class Importer {
content,
};
- // On cherche le dossier "D" (finalParentPath) pour lui pousser le fichier
+ // We find the final parent folder in the normalized structure and add the file to its children
const finalParentFolder = this.normalized_files.find(e => e.id === finalParentPath);
if (finalParentFolder && finalParentFolder.children) {
finalParentFolder.children.push(fileEntry);
} else {
- // Cas de secours si le fichier est à la racine absolue du glisser-déposer sans dossier
+ // If the parent folder doesn't exist (which shouldn't happen), we add the file to the root of normalized_files
this.normalized_files.push(fileEntry);
}
}
@@ -129,32 +139,32 @@ export class Importer {
while (to_process.length) {
const entry = to_process.shift()!;
- let tags = this.options.defaultValues.defaultTags;
- let description = this.options.defaultValues.defaultDescription;
+ let tags = this.options.defaultValues?.defaultTags;
+ let description = this.options.defaultValues?.defaultDescription;
let content = '';
if (this.options.extractFrontMatter && entry.filetype === 'text_based') {
const data = extractMetadataFromMarkdown(entry.content as string);
- tags = data.tags || this.options.defaultValues.defaultTags;
- description = data.description || this.options.defaultValues.defaultDescription;
+ tags = data.tags || this.options.defaultValues?.defaultTags;
+ description = data.description || this.options.defaultValues?.defaultDescription;
content = data.content_clean;
}
const parentId = entry.id.split('/').slice(0, -1).join('/') || undefined;
if (entry.filetype === 'text_based') {
this.nodes.push({
id: entry.id,
- parent_id: parentId,
+ parent_id: parentId || this.options.defaultValues?.defaultParent,
name: normalizeName(entry.filename) || 'Untitled',
description: description,
tags: tags,
- color: this.options.defaultValues.defaultColor || -1,
+ color: this.options.defaultValues?.defaultColor || -1,
role: 3,
- icon: this.options.defaultValues.defaultIcon,
- theme: this.options.defaultValues.defaultTheme,
- user_id: this.options.user_id,
+ icon: this.options.defaultValues?.defaultIcon,
+ theme: this.options.defaultValues?.defaultTheme,
content: content,
content_compiled: compile(content),
accessibility: 1,
access: 1,
+ user_id: '',
created_timestamp: this.options.preserveTimestamps ? entry.file.lastModified : Date.now(),
updated_timestamp: this.options.preserveTimestamps ? entry.file.lastModified : Date.now(),
});
@@ -163,21 +173,21 @@ export class Importer {
if (entry.filetype === 'folder') {
this.nodes.push({
id: entry.id,
- parent_id: parentId || this.options.defaultValues.defaultParent,
+ parent_id: parentId || this.options.defaultValues?.defaultParent,
name: normalizeName(entry.filename) || 'Untitled',
role: 2,
- user_id: this.options.user_id,
accessibility: 1,
access: 1,
created_timestamp: this.options.preserveTimestamps ? entry.file.lastModified : Date.now(),
updated_timestamp: this.options.preserveTimestamps ? entry.file.lastModified : Date.now(),
+ user_id: '',
});
}
if (entry.filetype === 'resource') {
resourceTasks.push({
- id: entry.id, // Le path d'origine pour mapper le parent_id plus tard
- parent_id: parentId,
+ id: entry.id,
+ parent_id: parentId || this.options.defaultValues?.defaultParent,
file: entry.file,
});
}
diff --git a/frontend/app/helpers/node.ts b/frontend/app/helpers/node.ts
index 7a9f1f86..615eda14 100644
--- a/frontend/app/helpers/node.ts
+++ b/frontend/app/helpers/node.ts
@@ -86,3 +86,28 @@ export const extractMetadataFromMarkdown = (markdown: string): { title: string;
return { ...metadata, content_clean: contentClean };
};
+
+export function parseTags(tags: string): string[] {
+ if (typeof tags === 'string') {
+ return tags
+ .split(',')
+ .map(tag => tag.trim())
+ .filter(Boolean);
+ }
+ return [];
+}
+
+export function mergeNode(node: Node, full_node: Node): Node {
+ const result: Node = { ...full_node };
+
+ for (const key in node) {
+ const localValue = node[key as keyof Node];
+ if (localValue !== undefined && localValue !== null && localValue !== '') {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (result as any)[key] = localValue; // keep local value if it's defined
+ }
+ }
+
+ result.partial = false;
+ return result;
+}
diff --git a/frontend/app/pages/dashboard/import/_components/ImportActions.vue b/frontend/app/pages/dashboard/import/_components/ImportActions.vue
index bb61cad3..7683c075 100644
--- a/frontend/app/pages/dashboard/import/_components/ImportActions.vue
+++ b/frontend/app/pages/dashboard/import/_components/ImportActions.vue
@@ -10,7 +10,7 @@
<Icon name="close" :size="16" />
{{ t('import.actions.cancel') }}
</AppButton>
- <AppButton type="primary" :disabled="isImporting || (toCreate.length === 0 && toUpdate.length === 0)" @click="importAll">
+ <AppButton type="primary" :disabled="isImporting || (importJob.toCreate.length === 0 && importJob.toUpdate.length === 0)" @click="importAll">
<Icon name="download" :size="16" />
{{ isImporting ? t('import.actions.importing') : t('import.actions.importAll') }}
</AppButton>
@@ -19,12 +19,10 @@
</template>
<script setup lang="ts">
-import type { DB_Node, ImportJob } from '~/stores';
+import type { ImportJob } from '~/helpers/backups/Importer';
const { t } = useI18nT();
const props = defineProps<{
- toCreate: DB_Node[];
- toUpdate: DB_Node[];
importJob: ImportJob;
resetImport: () => void;
importAll: () => void;
diff --git a/frontend/app/pages/dashboard/import/_components/ImportProgress.vue b/frontend/app/pages/dashboard/import/_components/ImportProgress.vue
index c97349e2..827ee4c8 100644
--- a/frontend/app/pages/dashboard/import/_components/ImportProgress.vue
+++ b/frontend/app/pages/dashboard/import/_components/ImportProgress.vue
@@ -2,8 +2,8 @@
<div class="container">
<div class="progress-header">
<span class="status">
- <strong>{{ t('common.labels.status') }}</strong
- ><span class="status-badge" :class="importJob.status"> {{ statusLabel }} </span>
+ <strong>{{ t('common.labels.status') }}</strong>
+ <span class="status-badge" :class="importJob.status"> {{ statusLabel }} </span>
</span>
<span v-if="importJob.status === 'in_progress'" class="progress-percent"> {{ progress }}% </span>
</div>
@@ -12,19 +12,22 @@
<div class="progress-bar" :style="{ width: progress + '%' }"></div>
</div>
- <small v-if="importJob.status === 'failed'">{{ importJob.error_message }}</small>
+ <small v-if="importJob.status === 'failed'">{{ importJob.error_message }} ({{ importJob.failures }} {{ t('common.status.failed') }})</small>
</div>
</template>
<script setup lang="ts">
-import type { ImportJob } from '~/stores';
+import type { ImportJob } from '~/helpers/backups/Importer';
-const props = defineProps<{ importJob: ImportJob; toCreate?: number; toUpdate?: number }>();
+const props = defineProps<{ importJob: ImportJob }>();
const { t } = useI18nT();
const progress = computed(() =>
- Math.floor(((props.importJob.created.length + props.importJob.updated.length) * 100) / ((props.toCreate || 0) + (props.toUpdate || 0))),
+ Math.floor(
+ ((props.importJob.created.length + props.importJob.updated.length) * 100) /
+ ((props.importJob.toCreate.length || 0) + (props.importJob.toUpdate.length || 0)),
+ ),
);
const statusLabel = computed(() => {
switch (props.importJob.status) {
diff --git a/frontend/app/pages/dashboard/import/_components/ImportSummary.vue b/frontend/app/pages/dashboard/import/_components/ImportSummary.vue
index 207ed027..61bd7db7 100644
--- a/frontend/app/pages/dashboard/import/_components/ImportSummary.vue
+++ b/frontend/app/pages/dashboard/import/_components/ImportSummary.vue
@@ -4,12 +4,12 @@
<div class="stats">
<div class="stat new">
<Icon name="plus" :size="20" />
- <span class="count">{{ toCreate }}</span>
+ <span class="count">{{ importJob.toCreate.length }}</span>
<span class="label">{{ t('import.summary.newDocuments') }}</span>
</div>
<div class="stat update">
<Icon name="update" :size="20" />
- <span class="count">{{ toUpdate }}</span>
+ <span class="count">{{ importJob.toUpdate.length }}</span>
<span class="label">{{ t('import.summary.documentsToUpdate') }}</span>
</div>
<div class="stat unchanged">
@@ -19,18 +19,16 @@
</div>
</div>
<div class="progess">
- <ImportProgress :import-job="importJob" :to-create="toCreate" :to-update="toUpdate" />
+ <ImportProgress :import-job="importJob" />
</div>
</div>
</template>
<script setup lang="ts">
import ImportProgress from './ImportProgress.vue';
-import type { ImportJob } from '~/stores';
+import type { ImportJob } from '~/helpers/backups/Importer';
defineProps<{
- toCreate: number;
- toUpdate: number;
unchangedCount: number;
importJob: ImportJob;
}>();
diff --git a/frontend/app/pages/dashboard/import/_components/ImportTabs.vue b/frontend/app/pages/dashboard/import/_components/ImportTabs.vue
index 2d06b1d2..d89bec3c 100644
--- a/frontend/app/pages/dashboard/import/_components/ImportTabs.vue
+++ b/frontend/app/pages/dashboard/import/_components/ImportTabs.vue
@@ -1,8 +1,12 @@
<template>
<div>
<div class="tabs">
- <button :class="{ active: activeTab === 'create' }" @click="activeTab = 'create'">{{ t('import.tabs.newDocuments') }} ({{ toCreate.length }})</button>
- <button :class="{ active: activeTab === 'update' }" @click="activeTab = 'update'">{{ t('import.tabs.updates') }} ({{ toUpdate.length }})</button>
+ <button :class="{ active: activeTab === 'create' }" @click="activeTab = 'create'">
+ {{ t('import.tabs.newDocuments') }} ({{ importJob.toCreate.length }})
+ </button>
+ <button :class="{ active: activeTab === 'update' }" @click="activeTab = 'update'">
+ {{ t('import.tabs.updates') }} ({{ importJob.toUpdate.length }})
+ </button>
<button :class="{ active: activeTab === 'local' }" @click="activeTab = 'local'">
{{ t('import.tabs.localSettings') }} ({{ manifest?.options.include_settings ? 1 : 0 }})
</button>
@@ -10,7 +14,7 @@
<!-- Tab: New Documents -->
<div v-if="activeTab === 'create'" class="tab-content">
- <div v-if="toCreate.length === 0" class="empty-state">
+ <div v-if="importJob.toCreate.length === 0" class="empty-state">
<Icon name="folder" :size="32" />
<p>{{ t('import.tabs.noNewDocuments') }}</p>
</div>
@@ -23,7 +27,7 @@
</div>
<div class="documents-list">
<NodeImportPreview
- v-for="doc in toCreate"
+ v-for="doc in importJob.toCreate"
:key="doc.id"
:node="doc"
selectable
@@ -38,7 +42,7 @@
<!-- Tab: Updates -->
<div v-if="activeTab === 'update'" class="tab-content">
- <div v-if="toUpdate.length === 0" class="empty-state">
+ <div v-if="importJob.toUpdate.length === 0" class="empty-state">
<Icon name="update" :size="32" />
<p>{{ t('import.tabs.noUpdates') }}</p>
</div>
@@ -52,7 +56,7 @@
</div>
<div class="documents-list">
<NodeImportPreview
- v-for="doc in toUpdate"
+ v-for="doc in importJob.toUpdate"
:key="doc.id"
:node="doc"
selectable
@@ -83,10 +87,11 @@
</template>
<script setup lang="ts">
-import type { DB_Node, ImportJob } from '~/stores';
+import type { DB_Node } from '~/stores';
import type { Manifest } from '~/helpers/backups/types';
+import type { ImportJob } from '~/helpers/backups/Importer';
-const props = defineProps<{ manifest: Manifest; toCreate: DB_Node[]; toUpdate: DB_Node[]; importJob: ImportJob }>();
+const props = defineProps<{ manifest: Manifest; importJob: ImportJob }>();
const emit = defineEmits<{
(e: 'import', type: 'create' | 'update', nodeIds: string[]): void;
(e: 'importLocalSettings'): void;
@@ -105,7 +110,7 @@ const isImporting = computed(() => props.importJob.status === 'in_progress');
function toggleSelectAllCreate(value: boolean) {
if (value) {
- selectedCreate.value = props.toCreate.map(d => d.id);
+ selectedCreate.value = props.importJob.toCreate.map(d => d.id);
} else {
selectedCreate.value = [];
}
@@ -123,7 +128,7 @@ function toggleSelection(id: string, type: 'create' | 'update') {
function toggleSelectAllUpdate(value: boolean) {
if (value) {
- selectedUpdate.value = props.toUpdate.map(d => d.id);
+ selectedUpdate.value = props.importJob.toUpdate.map(d => d.id);
} else {
selectedUpdate.value = [];
}
diff --git a/frontend/app/pages/dashboard/import/advanced.vue b/frontend/app/pages/dashboard/import/advanced.vue
index 472c2afd..1d0f70b8 100644
--- a/frontend/app/pages/dashboard/import/advanced.vue
+++ b/frontend/app/pages/dashboard/import/advanced.vue
@@ -11,49 +11,62 @@
<h3>{{ t('import.advanced.options') }}</h3>
<div class="actions-row">
- <AppToggle v-model="options.extractFrontMatter" />
+ <AppToggle v-model="importJob.options.extractFrontMatter" />
<p>{{ t('import.actions.extractFrontMatter') }}</p>
</div>
<div class="actions-row">
- <AppToggle v-model="options.normalizeLineEndings" />
+ <AppToggle v-model="importJob.options.normalizeLineEndings" />
<p>{{ t('import.actions.normalizeLineEndings') }}</p>
</div>
<div class="actions-row">
- <AppToggle v-model="options.preserveTimestamps" />
+ <AppToggle v-model="importJob.options.preserveTimestamps" />
<p>{{ t('import.actions.preserveTimestamps') }}</p>
</div>
<div>
<div>
<label for="default-parent">{{ t('import.advanced.defaultParent') }}</label>
- <AppSelect v-model="options.defaultValues.parent_id" class="entry" :items="categoriesItem" nullable :placeholder="t('common.labels.parent')" />
+ <AppSelect
+ v-model="importJob.options.defaultValues!!.defaultParent"
+ class="entry"
+ :items="categoriesItem"
+ nullable
+ :placeholder="t('common.labels.parent')"
+ />
</div>
<label for="default-description">
{{ t('import.advanced.defaultDescription') }}
</label>
- <input id="default-description" v-model="options.defaultValues.defaultDescription" type="text" placeholder="Default description for imported nodes" />
+ <input
+ id="default-description"
+ v-model="importJob.options.defaultValues!.defaultDescription"
+ type="text"
+ placeholder="Default description for imported nodes"
+ />
<label for="default-tags">
{{ t('import.advanced.defaultTags') }}
</label>
- <input id="default-tags" v-model="options.defaultValues.defaultTags" type="text" placeholder="tag1, tag2, tag3" />
+ <input id="default-tags" v-model="importJob.options.defaultValues!.defaultTags" type="text" placeholder="tag1, tag2, tag3" />
<label for="default-color">
{{ t('import.advanced.defaultColor') }}
</label>
- <AppColorPicker id="default-color" v-model="options.defaultValues.defaultColor" nullable />
+ <AppColorPicker id="default-color" v-model="importJob.options.defaultValues!.defaultColor" nullable />
<label for="default-thumbnail">
{{ t('import.advanced.defaultThumbnail') }}
</label>
- <input id="default-thumbnail" v-model="options.defaultValues.defaultThumbnail" type="text" />
+ <input id="default-thumbnail" v-model="importJob.options.defaultValues!.defaultThumbnail" type="text" />
<label for="default-icon">
{{ t('import.advanced.defaultIcon') }}
</label>
- <input id="default-icon" v-model="options.defaultValues.defaultIcon" type="text" />
+ <input id="default-icon" v-model="importJob.options.defaultValues!.defaultIcon" type="text" />
<label for="default-theme">
{{ t('import.advanced.defaultTheme') }}
</label>
- <AppSelect id="default-theme" v-model="options.defaultValues.defaultTheme" :items="DOCUMENT_THEMES" />
+ <AppSelect id="default-theme" v-model="importJob.options.defaultValues!.defaultTheme" :items="DOCUMENT_THEMES" />
</div>
+ <h3>{{ t('import.progress.title') }}</h3>
+ <ImportProgress :import-job="importJob" />
<section v-if="nodes.length" class="panel">
<div class="panel-head">
<h3>{{ t('import.files.toImport') }} ({{ totalItemsToImport }})</h3>
@@ -67,7 +80,6 @@
</AppButton>
</div>
</div>
- <ImportProgress :import-job="importJob" :to-create="toCreate" />
<div class="list">
<NodeImportPreview
v-for="node in nodes"
@@ -91,13 +103,12 @@
</template>
<script setup lang="ts">
import ImportProgress from './_components/ImportProgress.vue';
-import { Importer, type ResourceImportTask } from '~/helpers/backups/Importer';
+import { Importer, type ResourceImportTask, type ImportJob } from '~/helpers/backups/Importer';
import { DOCUMENT_THEMES } from '~/helpers/constants';
-import type { DB_Node, ImportJob } from '~/stores';
+import type { DB_Node } from '~/stores';
definePageMeta({ breadcrumb: { i18n: 'import.meta.breadcrumb' } });
-const user = useUserStore();
const nodesStore = useNodesStore();
const nodesTree = useNodesTree();
@@ -106,7 +117,6 @@ const { t } = useI18nT();
const categoriesItem = nodesTree.getTreeUpToRole(2);
const selectedNodes = ref<string[]>([]);
-const toCreate = ref(0);
const files = ref<File[]>([]);
const nodes = ref<DB_Node[]>([]);
@@ -114,23 +124,31 @@ const resourcesToUpload = ref<ResourceImportTask[]>([]);
const totalItemsToImport = computed(() => nodes.value.length + resourcesToUpload.value.length);
-const options = ref({
- extractFrontMatter: true,
- normalizeLineEndings: true,
- preserveTimestamps: true,
- defaultValues: {
- parent_id: undefined,
- defaultDescription: '',
- defaultTags: '',
- defaultColor: -1,
- defaultThumbnail: '',
- defaultIcon: '',
- defaultTheme: '',
+const importJob = ref<ImportJob>({
+ status: 'pending',
+ toCreate: [],
+ toUpdate: [],
+ created: [],
+ updated: [],
+ failures: 0,
+ options: {
+ extractFrontMatter: true,
+ normalizeLineEndings: true,
+ preserveTimestamps: true,
+ defaultValues: {
+ defaultParent: undefined,
+ defaultDescription: '',
+ defaultTags: '',
+ defaultColor: -1,
+ defaultThumbnail: '',
+ defaultIcon: '',
+ defaultTheme: '',
+ },
},
});
watch(
- () => options.value,
+ () => importJob.value,
_ => {
// Re-process files with new options
if (files.value.length) processImport();
@@ -138,15 +156,6 @@ watch(
{ deep: true },
);
-const importJob = ref<ImportJob>({
- status: 'pending',
- toCreate: 0,
- toUpdate: 0,
- created: [],
- updated: [],
- failures: 0,
-});
-
function selectFiles(importedFiles: File | File[] | null) {
if (!importedFiles) return;
files.value = Array.isArray(importedFiles) ? importedFiles : [importedFiles];
@@ -155,10 +164,7 @@ function selectFiles(importedFiles: File | File[] | null) {
async function processImport() {
if (!files.value) return;
- const imp = new Importer({
- ...options.value,
- user_id: user.user!.id,
- });
+ const imp = new Importer(importJob.value.options);
await imp.handleFiles(files.value);
const result = await imp.normalizedToNodes();
@@ -186,17 +192,11 @@ const importSelected = () => {
const importAll = () => importNodes(nodes.value, resourcesToUpload.value);
async function importNodes(nodesToImport: DB_Node[], resourcesImport: ResourceImportTask[]) {
- const totalCount = nodesToImport.length + resourcesImport.length;
- toCreate.value = totalCount;
- importJob.value.toCreate = totalCount;
- importJob.value.status = 'in_progress';
-
- await nodesStore.importAllNodesAndResources(nodesToImport, resourcesImport, importJob);
-
- nodes.value = nodes.value.filter(n => !importJob.value.created.includes(n.id));
- resourcesToUpload.value = resourcesToUpload.value.filter(r => !importJob.value.created.includes(r.id));
-
- importJob.value.status = 'completed';
+ importJob.value.toCreate = nodesToImport;
+ importJob.value.toUpdate = [];
+ await nodesStore.importAllNodesAndResources({ toCreate: nodesToImport, toUpdate: [], resources: resourcesImport }, importJob);
+ nodes.value = [];
+ resourcesToUpload.value = [];
}
</script>
diff --git a/frontend/app/pages/dashboard/import/backup.vue b/frontend/app/pages/dashboard/import/backup.vue
index 6f3e3cb1..05f3cfea 100644
--- a/frontend/app/pages/dashboard/import/backup.vue
+++ b/frontend/app/pages/dashboard/import/backup.vue
@@ -23,24 +23,15 @@
<ImportHeader :manifest="manifest" :reset-import="resetImport" />
<!-- Import Summary -->
- <SummaryCard :to-create="toCreate.length" :to-update="toUpdate.length" :unchanged-count="unchangedCount" :import-job="importJob" />
+ <SummaryCard :unchanged-count="unchangedCount" :import-job="importJob" />
<!-- Tabs for New / Updates -->
- <ImportTabs
- :manifest="manifest"
- :to-create="toCreate"
- :to-update="toUpdate"
- :import-job="importJob"
- @import="importNodes"
- @import-local-settings="importLocalSettings"
- />
+ <ImportTabs :manifest="manifest" :import-job="importJob" @import="importNodes" @import-local-settings="importLocalSettings" />
<!-- Import All Actions -->
<ImportActions
- v-model:preserve-timestamps="importOptions.preserveTimestamps"
+ v-model:preserve-timestamps="importJob.options.preserveTimestamps"
v-model:skip-existing="importOptions.skipExisting"
- :to-create="toCreate"
- :to-update="toUpdate"
:reset-import="resetImport"
:import-all="importAll"
:import-job="importJob"
@@ -55,8 +46,9 @@ import SummaryCard from './_components/ImportSummary.vue';
import ImportTabs from './_components/ImportTabs.vue';
import ImportActions from './_components/ImportActions.vue';
import { handleBackupFile } from '~/helpers/backups';
+import type { ImportJob } from '~/helpers/backups/Importer';
import type { Manifest } from '~/helpers/backups/types';
-import type { DB_Node, ImportJob } from '~/stores/db_structures';
+import type { DB_Node } from '~/stores/db_structures';
definePageMeta({ breadcrumb: { i18n: 'import.meta.breadcrumb' } });
@@ -74,30 +66,28 @@ const analyzeError = ref('');
// Backup data
const manifest = ref<Manifest | null>(null);
const backupDocuments = ref<DB_Node[]>([]);
-const toCreate = ref<DB_Node[]>([]);
-const toUpdate = ref<DB_Node[]>([]);
const localData = ref<object | null>(null);
// Import state
const importJob = ref<ImportJob>({
status: 'pending',
- toCreate: 0,
- toUpdate: 0,
+ toCreate: [],
+ toUpdate: [],
created: [],
updated: [],
failures: 0,
+ options: {
+ preserveTimestamps: false,
+ },
});
-// Options
const importOptions = reactive({
- preserveTimestamps: false,
skipExisting: false,
});
-// Computed
const unchangedCount = computed(() => {
if (!backupDocuments.value.length) return 0;
- return backupDocuments.value.length - toCreate.value.length - toUpdate.value.length;
+ return backupDocuments.value.length - importJob.value.toCreate.length - importJob.value.toUpdate.length;
});
// Methods
@@ -120,12 +110,12 @@ async function analyzeFile() {
if (result.documents?.length) {
backupDocuments.value = result.documents;
const { toCreate: create, toUpdate: update } = nodesStore.prepareImport(result.documents);
- toCreate.value = create;
- toUpdate.value = update;
+ importJob.value.toCreate = create;
+ importJob.value.toUpdate = update;
} else {
backupDocuments.value = [];
- toCreate.value = [];
- toUpdate.value = [];
+ importJob.value.toCreate = [];
+ importJob.value.toUpdate = [];
}
step.value = 'preview';
@@ -141,30 +131,32 @@ function resetImport() {
selectedFile.value = undefined;
manifest.value = null;
backupDocuments.value = [];
- toCreate.value = [];
- toUpdate.value = [];
+ importJob.value.toCreate = [];
+ importJob.value.toUpdate = [];
importJob.value = {
status: 'pending',
- toCreate: 0,
- toUpdate: 0,
+ toCreate: [],
+ toUpdate: [],
created: [],
updated: [],
failures: 0,
+ options: {
+ preserveTimestamps: false,
+ },
};
}
async function importNodes(type: 'create' | 'update', ids: string[]) {
- const nodes: DB_Node[] = type === 'create' ? toCreate.value.filter(d => ids.includes(d.id)) : toUpdate.value.filter(d => ids.includes(d.id));
+ const nodes: DB_Node[] =
+ type === 'create' ? importJob.value.toCreate.filter(d => ids.includes(d.id)) : importJob.value.toUpdate.filter(d => ids.includes(d.id));
if (type === 'create') {
- importJob.value.toCreate = nodes.length;
- await nodesStore.importMultipleNodes({ toCreate: nodes, toUpdate: [] }, importJob);
- toCreate.value = toCreate.value.filter(d => !importJob.value.created.includes(d.id));
+ await nodesStore.importAllNodesAndResources({ toCreate: nodes, toUpdate: [], resources: [] }, importJob);
+ importJob.value.toCreate = importJob.value.toCreate.filter(d => !importJob.value.created.includes(d.id));
} else if (type == 'update') {
- importJob.value.toUpdate = nodes.length;
- await nodesStore.importMultipleNodes({ toCreate: [], toUpdate: nodes }, importJob);
- toUpdate.value = toUpdate.value.filter(d => !importJob.value.updated.includes(d.id));
+ await nodesStore.importAllNodesAndResources({ toCreate: [], toUpdate: nodes, resources: [] }, importJob);
+ importJob.value.toUpdate = importJob.value.toUpdate.filter(d => !importJob.value.updated.includes(d.id));
}
notifications.add({
@@ -195,15 +187,12 @@ function importLocalSettings() {
}
async function importAll() {
- const createDocs = toCreate.value;
- const updateDocs = importOptions.skipExisting ? [] : toUpdate.value;
-
- importJob.value.toCreate = createDocs.length;
- importJob.value.toUpdate = updateDocs.length;
+ const createDocs = importJob.value.toCreate;
+ const updateDocs = importOptions.skipExisting ? [] : importJob.value.toUpdate;
- await nodesStore.importMultipleNodes({ toCreate: createDocs, toUpdate: updateDocs }, importJob);
- toCreate.value = toCreate.value.filter(d => !importJob.value.created.includes(d.id));
- toUpdate.value = toUpdate.value.filter(d => !importJob.value.updated.includes(d.id));
+ await nodesStore.importAllNodesAndResources({ toCreate: createDocs, toUpdate: updateDocs, resources: [] }, importJob);
+ importJob.value.toCreate = importJob.value.toCreate.filter(d => !importJob.value.created.includes(d.id));
+ importJob.value.toUpdate = importJob.value.toUpdate.filter(d => !importJob.value.updated.includes(d.id));
notifications.add({
type: 'success',
diff --git a/frontend/app/pages/dashboard/import/files.vue b/frontend/app/pages/dashboard/import/files.vue
index c2b2d837..f5bf0a29 100644
--- a/frontend/app/pages/dashboard/import/files.vue
+++ b/frontend/app/pages/dashboard/import/files.vue
@@ -20,7 +20,7 @@
</AppButton>
</div>
</div>
- <ImportProgress :import-job="importJob" :to-create="toCreate" />
+ <ImportProgress :import-job="importJob" />
<div class="list">
<NodeImportPreview
v-for="node in nodes"
@@ -38,32 +38,26 @@
<script setup lang="ts">
import ImportProgress from './_components/ImportProgress.vue';
-import { Importer } from '~/helpers/backups/Importer';
-import type { DB_Node, ImportJob } from '~/stores';
+import { Importer, type ImportJob } from '~/helpers/backups/Importer';
+import type { DB_Node } from '~/stores';
definePageMeta({ breadcrumb: { i18n: 'import.meta.breadcrumb' } });
-const user = useUserStore();
const nodesStore = useNodesStore();
const { t } = useI18nT();
const selectedNodes = ref<string[]>([]);
-const toCreate = ref(0);
const nodes = ref<DB_Node[]>([]);
const importJob = ref<ImportJob>({
status: 'pending',
- toCreate: 0,
- toUpdate: 0,
+ toCreate: [],
+ toUpdate: [],
created: [],
updated: [],
failures: 0,
-});
-
-async function selectFiles(files: File | File[] | null) {
- if (!files) return;
- const imp = new Importer({
+ options: {
extractFrontMatter: true,
normalizeLineEndings: true,
preserveTimestamps: false,
@@ -75,8 +69,12 @@ async function selectFiles(files: File | File[] | null) {
defaultTheme: '',
defaultThumbnail: '',
},
- user_id: user.user!.id,
- });
+ },
+});
+
+async function selectFiles(files: File | File[] | null) {
+ if (!files) return;
+ const imp = new Importer(importJob.value.options);
await imp.handleFiles(files);
nodes.value = (await imp.normalizedToNodes()).nodesToCreate;
}
@@ -95,9 +93,8 @@ const importSelected = () => {
const importAll = () => importNodes(nodes.value);
async function importNodes(importNodes: DB_Node[]) {
- toCreate.value = importNodes.length;
- importJob.value.toCreate = importNodes.length;
- await nodesStore.importMultipleNodes({ toCreate: importNodes, toUpdate: [] }, importJob);
+ importJob.value.toCreate = importNodes;
+ await nodesStore.importAllNodesAndResources({ toCreate: importNodes, toUpdate: [], resources: [] }, importJob);
nodes.value = nodes.value.filter(n => !importJob.value.created.includes(n.id));
}
</script>
diff --git a/frontend/app/stores/db_structures.d.ts b/frontend/app/stores/db_structures.d.ts
index 9c94d05a..e3c80caa 100644
--- a/frontend/app/stores/db_structures.d.ts
+++ b/frontend/app/stores/db_structures.d.ts
@@ -148,15 +148,3 @@ export interface OverviewStats {
total_nodes: number;
total_size: number;
}
-
-// Internal structures
-
-export interface ImportJob {
- status: 'pending' | 'in_progress' | 'completed' | 'failed';
- toCreate: number;
- created: string[];
- toUpdate: number;
- updated: string[];
- failures: number;
- error_message?: string;
-}
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index cea352d0..5a59fe41 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -1,7 +1,8 @@
-import type { ResourceImportTask } from '~/helpers/backups/Importer';
import { Collection } from './collection';
import { IndexedCollection } from '~/helpers/IndexedCollection';
-import type { DB_Node, ImportJob, InvitationJoinResponse, Node, NodeInvitation, NodeSearchResult, Permission, PublicNodeResponse } from './db_structures';
+import { parseTags, mergeNode } from '~/helpers/node';
+import type { DB_Node, InvitationJoinResponse, Node, NodeInvitation, NodeSearchResult, Permission, PublicNodeResponse } from './db_structures';
+import type { ImportJob, ResourceImportTask } from '~/helpers/backups/Importer';
export type TeamRole = 0;
export type CategoryRole = 1 | 2;
@@ -511,7 +512,6 @@ export const useNodesStore = defineStore('nodes', {
if (!existingNode) {
toCreate.push(backupNode);
} else {
- // Check if any field is different
if (backupNode.updated_timestamp !== existingNode.updated_timestamp) {
toUpdate.push(backupNode);
}
@@ -519,67 +519,30 @@ export const useNodesStore = defineStore('nodes', {
}
return { toCreate, toUpdate };
},
- async importAllNodesAndResources(nodes: DB_Node[], resources: ResourceImportTask[], job: Ref<ImportJob>) {
- const nodesById = new Map(nodes.map(n => [n.id, n]));
- const corresponding: Record<string, string> = {}; // Map: [old_id] -> [new_server_id]
-
- const resourcesStore = useResourcesStore();
-
- // 1. Start by importing all nodes (folders, documents) to get their new IDs
- for (const node of nodes) {
- await this.importNode(node, nodesById, corresponding, job);
- }
-
- // 2. Import resources (binary files) and map their parent_id to the new IDs
- for (const task of resources) {
- try {
- let finalParentId = undefined;
- if (task.parent_id) {
- finalParentId = corresponding[task.parent_id] || task.parent_id;
- } else {
- finalParentId = usePreferencesStore().get('defaultUploadFolder').value;
- }
-
- const formData = new FormData();
- formData.append('file', task.file);
- if (finalParentId) formData.append('parent_id', finalParentId);
-
- console.log(`[Import] Uploading resource file: ${task.file.name} to parent: ${finalParentId}`);
- const uploadedResourceNode = await resourcesStore.post(formData);
-
- job.value.created.push(uploadedResourceNode.id);
-
- await new Promise(resolve => setTimeout(resolve, 50));
- } catch (error) {
- console.error(`[Import] Failed to upload resource ${task.file.name}:`, error);
- }
- }
- },
-
- async importMultipleNodes(nodes: { toCreate: DB_Node[]; toUpdate: DB_Node[] }, job: Ref<ImportJob>) {
+ async importAllNodesAndResources(nodes: { toCreate: DB_Node[]; toUpdate: DB_Node[]; resources: ResourceImportTask[] }, job: Ref<ImportJob>) {
job.value.status = 'in_progress';
+ job.value.failures = 0;
try {
- await this.importAllNodes(nodes.toCreate, job);
+ const corresponding: Record<string, string> = {};
+ await this.importAllNodes(nodes.toCreate, job, corresponding);
await this.updateAllNodes(nodes.toUpdate, job);
+ await this.importAllResources(nodes.resources, job, corresponding);
job.value.status = 'completed';
} catch (error) {
job.value.status = 'failed';
job.value.error_message = (error as Error).message;
}
},
- async importAllNodes(nodes: DB_Node[], job: Ref<ImportJob>) {
+
+ async importAllNodes(nodes: DB_Node[], job: Ref<ImportJob>, corresponding: Record<string, string>) {
const nodesById = new Map(nodes.map(n => [n.id, n]));
- const corresponding: Record<string, string> = {};
for (const node of nodes) {
await this.importNode(node, nodesById, corresponding, job);
}
},
async importNode(node: DB_Node, nodesById: Map<string, DB_Node>, corresponding: Record<string, string>, job: Ref<ImportJob>): Promise<void> {
- // Already imported
- if (corresponding[node.id]) return;
-
- // Handle the parent
+ if (corresponding[node.id]) return; // Already imported
if (node.parent_id && !this.getById(node.parent_id)) {
const newParentId = corresponding[node.parent_id];
@@ -588,24 +551,19 @@ export const useNodesStore = defineStore('nodes', {
const parent = nodesById.get(node.parent_id); // Parent from the backup (future import)
if (parent) {
- // Import the parent first
- await this.importNode(parent, nodesById, corresponding, job);
+ await this.importNode(parent, nodesById, corresponding, job); // Import the parent first
} else {
- // Parent not found → detach
- delete node.parent_id;
+ delete node.parent_id; // Parent not found → detach
}
}
- // Update parent_id after import
- if (corresponding[node.parent_id!]) {
- node.parent_id = corresponding[node.parent_id!];
- }
+ if (corresponding[node.parent_id!]) node.parent_id = corresponding[node.parent_id!]; // Update parent_id after import
}
// Import of the node
- const res = await this.post(node);
+ const res = await this.post({ ...node, user_id: undefined });
job.value.created.push(node.id);
- await new Promise(resolve => setTimeout(resolve, 75)); // slight delay to avoid overwhelming the server
+ await new Promise(resolve => setTimeout(resolve, 75));
corresponding[node.id] = res.id;
},
@@ -614,7 +572,35 @@ export const useNodesStore = defineStore('nodes', {
if (!this.getById(node.id)) continue;
await this.update({ ...(node as Node), partial: false, shared: false, permissions: [] });
if (job) job.value.updated.push(node.id);
- await new Promise(resolve => setTimeout(resolve, 75)); // slight delay to avoid overwhelming the server
+ await new Promise(resolve => setTimeout(resolve, 75));
+ }
+ },
+
+ async importAllResources(resources: ResourceImportTask[], job: Ref<ImportJob>, corresponding: Record<string, string>) {
+ const preferences = usePreferencesStore();
+ const defaultUploadFolder = preferences.get('defaultUploadFolder').value;
+ const resourcesStore = useResourcesStore();
+ for (const task of resources) {
+ try {
+ let finalParentId = undefined;
+ if (task.parent_id) finalParentId = corresponding[task.parent_id] || task.parent_id;
+ else {
+ if (job.value.options?.defaultValues?.defaultParent) finalParentId = job.value.options.defaultValues.defaultParent;
+ else if (defaultUploadFolder) finalParentId = defaultUploadFolder;
+ }
+
+ const formData = new FormData();
+ formData.append('file', task.file);
+ if (finalParentId) formData.append('parent_id', finalParentId);
+
+ const uploadedResourceNode = await resourcesStore.post(formData);
+
+ job.value.created.push(uploadedResourceNode.id);
+
+ await new Promise(resolve => setTimeout(resolve, 50));
+ } catch (error) {
+ console.error(`[Import] Failed to upload resource ${task.file.name}:`, error);
+ }
}
},
@@ -627,27 +613,4 @@ export const useNodesStore = defineStore('nodes', {
},
});
-function parseTags(tags: string): string[] {
- if (typeof tags === 'string') {
- return tags
- .split(',')
- .map(tag => tag.trim())
- .filter(Boolean);
- }
- return [];
-}
-
-function mergeNode(node: Node, full_node: Node): Node {
- const result: Node = { ...full_node };
-
- for (const key in node) {
- const localValue = node[key as keyof Node];
- if (localValue !== undefined && localValue !== null && localValue !== '') {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (result as any)[key] = localValue; // keep local value if it's defined
- }
- }
-
- result.partial = false;
- return result;
-}
+// Helper functions
diff --git a/frontend/i18n/locales/de/import.ts b/frontend/i18n/locales/de/import.ts
index 42df7e77..a987475d 100644
--- a/frontend/i18n/locales/de/import.ts
+++ b/frontend/i18n/locales/de/import.ts
@@ -42,7 +42,7 @@ export default {
},
advanced: {
title: 'Erweiterter Import',
- description: 'Importiere Dokumente mit angepassten Optionen für maximale Kontrolle.',
+ description: 'Importiere gesamte Ordner (einschließlich Unterordner & Uploads) mit benutzerdefinierten Optionen für maximale Kontrolle.',
},
},
@@ -75,6 +75,10 @@ export default {
localImportedTitle: 'Lokale Einstellungen importiert',
},
+ progress: {
+ title: 'Importfortschritt',
+ },
+
steps: {
select: {
analyzing: 'Analysiere...',
diff --git a/frontend/i18n/locales/en/import.ts b/frontend/i18n/locales/en/import.ts
index 8f1a83ff..0b5d7aad 100644
--- a/frontend/i18n/locales/en/import.ts
+++ b/frontend/i18n/locales/en/import.ts
@@ -42,7 +42,7 @@ export default {
},
advanced: {
title: 'Advanced import',
- description: 'Import documents using custom options for maximum control.',
+ description: 'Import entire folder (including subfolders & uploads) using custom options for maximum control.',
},
},
@@ -75,6 +75,10 @@ export default {
localImportedTitle: 'Local settings imported',
},
+ progress: {
+ title: 'Import progress',
+ },
+
steps: {
select: {
analyzing: 'Analyzing...',
diff --git a/frontend/i18n/locales/fr/import.ts b/frontend/i18n/locales/fr/import.ts
index dc9d5db5..80960ee8 100644
--- a/frontend/i18n/locales/fr/import.ts
+++ b/frontend/i18n/locales/fr/import.ts
@@ -42,7 +42,8 @@ export default {
},
advanced: {
title: 'Importation avancée',
- description: 'Importez des documents en utilisant des options personnalisées pour un contrôle maximum.',
+ description:
+ 'Importer un dossier entier (y compris les sous-dossiers et les téléchargements) en utilisant des options personnalisées pour un contrôle maximal.',
},
},
@@ -75,6 +76,10 @@ export default {
localImportedTitle: 'Paramètres locaux importés',
},
+ progress: {
+ title: "Avancement de l'importation",
+ },
+
steps: {
select: {
analyzing: 'Analyse en cours...',
diff --git a/frontend/i18n/locales/uk/import.ts b/frontend/i18n/locales/uk/import.ts
index 25d45efd..7bd54c20 100644
--- a/frontend/i18n/locales/uk/import.ts
+++ b/frontend/i18n/locales/uk/import.ts
@@ -42,7 +42,7 @@ export default {
},
advanced: {
title: 'Розширений імпорт',
- description: 'Імпортуйте документи з використанням власних параметрів для максимального контролю.',
+ description: 'Імпортуйте цілу папку (включаючи підпапки та завантаження) за допомогою спеціальних параметрів для максимального контролю.',
},
},
@@ -75,6 +75,10 @@ export default {
localImportedTitle: 'Імпортовано локальні налаштування',
},
+ progress: {
+ title: 'Прогрес імпорту',
+ },
+
steps: {
select: {
analyzing: 'Аналіз...',