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.

Optimizations: Now store data as map

Smaug673969af602f1ee1
diff --git a/frontend/app/.env.production b/frontend/app/.env.production
index 30dc16bf..a11ac8ed 100644
--- a/frontend/app/.env.production
+++ b/frontend/app/.env.production
@@ -1,2 +1,2 @@
-VITE_BASE_API="http://localhost:8201"
-VITE_BASE_CDN="http://localhost:9000/alexandrie"
\ No newline at end of file
+VITE_BASE_API="https://api.alexandrie-hub.fr"
+VITE_BASE_CDN="https://cdn.alexandrie-hub.fr"
\ No newline at end of file
diff --git a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
index 9cbb5362..ef3c93c6 100644
--- a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
+++ b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
@@ -129,17 +129,17 @@ const showFilters = ref(true);
const showSuggestions = ref(false);
const selectedSuggestionIndex = ref(0);
-const documentStore = useNodesStore();
+const nodesStore = useNodesStore();
const categoriesTree = new TreeStructure(useSidebarTree().nodes.value.filter(n => n.data.role <= 2)).generateTree();
const filteredTagSuggestions = computed(() => {
if (!tagInput.value) return [];
const input = tagInput.value.toLowerCase();
- return documentStore.allTags.filter(tag => tag.toLowerCase().includes(input) && !selectedTags.value.includes(tag)).slice(0, 5);
+ return nodesStore.allTags.filter(tag => tag.toLowerCase().includes(input) && !selectedTags.value.includes(tag)).slice(0, 5);
});
const filteredDocuments = computed(() => {
- return documentStore.search({
+ return nodesStore.search({
query: props.query,
category: selectedCategory.value,
dateType: dateType.value,
@@ -154,7 +154,7 @@ const flattenedItems = computed(() => {
id: doc.id,
icon: getDocumentIcon(doc),
title: doc.name,
- description: doc.tags ? `#${String(doc.tags)}` : 'Document',
+ description: doc.tags ? `#${String(doc.tags.split(', ').join(' #'))}` : 'Document',
path: `/dashboard/docs/${doc.id}`,
section: '',
globalIndex: idx,
@@ -227,7 +227,7 @@ function clearFilters() {
}
function getDocumentIcon(doc: Node) {
- if (doc.order ?? 0 < 0) return 'pin';
+ if (doc.order == -1) return 'pin';
return 'files';
}
diff --git a/frontend/app/components/MarkdownEditor/ImageSelectorModal.vue b/frontend/app/components/MarkdownEditor/ImageSelectorModal.vue
index fd03059e..9474f8d4 100644
--- a/frontend/app/components/MarkdownEditor/ImageSelectorModal.vue
+++ b/frontend/app/components/MarkdownEditor/ImageSelectorModal.vue
@@ -9,7 +9,7 @@
<input v-model="searchQuery" placeholder="Search images..." class="search-input" />
</div>
<div class="images-grid">
- <div v-for="image in filteredImages" :key="image.id" class="image-item" @click="selectImage(image)">
+ <div v-for="image in filteredImages.values()" :key="image.id" class="image-item" @click="selectImage(image)">
<img :src="resolvePreviewUrl(image)" :alt="image.name" class="image-preview" @error="handleImageError" />
<div class="image-info">
<span class="image-name">{{ image.name }}</span>
@@ -18,7 +18,7 @@
</div>
</div>
- <div v-if="filteredImages.length === 0" class="no-images">
+ <div v-if="filteredImages.size === 0" class="no-images">
<p>No images found</p>
</div>
</div>
diff --git a/frontend/app/components/QuickSearch.vue b/frontend/app/components/QuickSearch.vue
index 25a11509..fc33d5ed 100644
--- a/frontend/app/components/QuickSearch.vue
+++ b/frontend/app/components/QuickSearch.vue
@@ -24,13 +24,15 @@
const categoryStore = useNodesStore();
const documents = computed(() =>
- useNodesStore().getAll.filter(c => c.name.toLowerCase().includes(filter.value.toLowerCase()) || c.tags?.toLowerCase().includes(filter.value.toLowerCase())),
+ useNodesStore().documents.filter(
+ c => c.name.toLowerCase().includes(filter.value.toLowerCase()) || (typeof c.tags === 'string' && c.tags.toLowerCase().includes(filter.value.toLowerCase())),
+ ),
);
const filter = ref<string>('');
const showSearchModal = ref<boolean>(false);
// Docs = max 5 docs
-const docs = computed(() => documents.value.slice(0, 5));
+const docs = computed(() => documents.value.toArray().slice(0, 5));
const close = () => {
showSearchModal.value = false;
diff --git a/frontend/app/components/Sidebar/SidebarItem.vue b/frontend/app/components/Sidebar/SidebarItem.vue
index 8b587c4b..db16d5d5 100644
--- a/frontend/app/components/Sidebar/SidebarItem.vue
+++ b/frontend/app/components/Sidebar/SidebarItem.vue
@@ -42,7 +42,7 @@ const customClass = computed(() => {
return 'default-icon';
});
const icon = computed(() => {
- if ('icon' in props.item.data && props.item.data.icon) return props.item.data.icon;
+ if (props.item.data.icon) return props.item.data.icon;
return props.item.icon || '';
});
diff --git a/frontend/app/components/Sidebar/helpers.ts b/frontend/app/components/Sidebar/helpers.ts
index 6a88d326..d8bee4a4 100644
--- a/frontend/app/components/Sidebar/helpers.ts
+++ b/frontend/app/components/Sidebar/helpers.ts
@@ -1,7 +1,7 @@
import SettingsModal from '@/pages/dashboard/settings/modal.vue';
import type { Node } from '@/stores';
-export type DefaultItem = Item<Omit<Node, 'user_id' | 'data' | 'show' | 'access' | 'created_timestamp' | 'updated_timestamp'>>;
+export type DefaultItem = Item<Omit<Node, 'user_id' | 'data' | 'show' | 'access' | 'accessibility' | 'created_timestamp' | 'updated_timestamp'>>;
export interface Workspace {
text: string;
value?: string;
diff --git a/frontend/app/composables/TreeStructure.ts b/frontend/app/composables/TreeStructure.ts
index a636f53c..f5e40e77 100644
--- a/frontend/app/composables/TreeStructure.ts
+++ b/frontend/app/composables/TreeStructure.ts
@@ -78,6 +78,24 @@ export class TreeStructure {
childrens: children.map(child => this.buildTree(child, newVisited)),
};
}
+
+ public next(id?: string): Item | undefined {
+ const item = this.itemMap.get(id || '');
+ if (!item) return undefined;
+ const childrens = this.childrenMap.get(item.parent_id || '')?.filter(c => c.data.role === 3) || [];
+ const index = childrens.findIndex(child => child.id === id);
+ if (index === -1 || index === childrens.length - 1) return undefined;
+ return childrens[index + 1];
+ }
+
+ public previous(id?: string): Item | undefined {
+ const item = this.itemMap.get(id || '');
+ if (!item) return undefined;
+ const childrens = this.childrenMap.get(item.parent_id || '')?.filter(c => c.data.role === 3) || [];
+ const index = childrens.findIndex(child => child.id === id);
+ if (index === -1 || index === 0) return undefined;
+ return childrens[index - 1];
+ }
}
export const filterRecursive = <T extends ANode>(items: T[], filter: Ref<string>): T[] => {
return items
diff --git a/frontend/app/composables/useNodesTree.ts b/frontend/app/composables/useNodesTree.ts
index a4b2b74f..edbf00b5 100644
--- a/frontend/app/composables/useNodesTree.ts
+++ b/frontend/app/composables/useNodesTree.ts
@@ -1,14 +1,16 @@
import type { Node } from '~/stores';
-const preferencesStore = usePreferences();
-
let nodes: ComputedRef<Item<Node>[]> | Ref<Item<Node>[]> = ref([]);
const structure = computed(() => new TreeStructure(nodes.value));
+const preferences = usePreferences();
const resolveIcon = (item: Node) => {
if (item.role === 1) return item.icon || 'workspace';
if (item.role === 2) return item.icon || (item.shared ? 'shared_folder' : 'folder');
- if (item.role === 3) return item.accessibility == 1 ? 'file' : item.accessibility == 2 ? 'draft' : 'shared_doc';
+ if (item.role === 3) {
+ if (!preferences.get('normalizeFileIcons').value && structure.value.childrenMap.get(item.id)?.length) return 'file_parent';
+ return item.accessibility == 1 ? 'file' : item.accessibility == 2 ? 'draft' : 'shared_doc';
+ }
if (item.role === 4) return item.metadata?.filetype == 'application/pdf' ? 'pdf' : 'image';
return 'file';
};
@@ -22,25 +24,10 @@ const resolveLink = (item: Node) => {
/* Do operations in the tree and return the final tree */
const tree = computed(() => {
- if (!preferencesStore.get('normalizeFileIcons').value) {
- for (const i of structure.value.childrenMap.keys()) {
- const ref = structure.value.itemMap.get(i);
- const subs = structure.value.childrenMap.get(i);
- if (ref?.data.role === 3 && subs?.some(c => c.data.role != 4)) {
- structure.value.itemMap.get(i)!.icon = 'file_parent';
- }
- }
- }
-
return structure.value.generateTree();
});
-const collapseAll = () => {
- nodes.value.forEach(item => {
- if (item.show.value) item.show.value = false;
- collapseAllStates();
- });
-};
+const collapseAll = collapseAllStates;
const getSubTreeById = (id: string) => {
return structure.value.treeToArray(structure.value.getSubTreeById(id)?.childrens || []);
};
@@ -64,10 +51,6 @@ function useSidebarTree() {
data: node,
show: ref(getCollapseState(node.id)),
}))
- .sort((a, b) => {
- if ((a.data.order ?? 0) !== (b.data.order ?? 0)) return (a.data.order ?? 0) - (b.data.order ?? 0);
- return a.data.name.localeCompare(b.data.name);
- })
.sort((a, b) => (a.data.order ?? 0) - (b.data.order ?? 0) || a.data.name.localeCompare(b.data.name))
: [],
);
diff --git a/frontend/app/pages/dashboard/cdn/index.vue b/frontend/app/pages/dashboard/cdn/index.vue
index 616558ec..0b713584 100644
--- a/frontend/app/pages/dashboard/cdn/index.vue
+++ b/frontend/app/pages/dashboard/cdn/index.vue
@@ -18,7 +18,7 @@
<template #bulk-actions="{ selected }">
<div class="bulk-actions">
<span class="selected-count">{{ selected.length }}</span>
- <span style=" height: 32px; border-left: 1px solid var(--border-color);margin-left: 4px"></span>
+ <span style="height: 32px; border-left: 1px solid var(--border-color); margin-left: 4px"></span>
<Icon name="delete" fill="var(--font-color-light)" class="action-btn" @click="bulkDelete(selected)" />
</div>
</template>
@@ -61,7 +61,7 @@ const fileLink = ref('');
const isLoading = ref(false);
const dropComponent = ref();
-const sortedRessources = computed(() => [...nodesStore.ressources].sort((a, b) => b.created_timestamp - a.created_timestamp));
+const sortedRessources = computed(() => nodesStore.ressources.toArray().sort((a, b) => b.created_timestamp - a.created_timestamp));
const selectFile = (file?: File) => (selectedFile.value = file);
const copyLink = () => navigator.clipboard.writeText(fileLink.value!);
@@ -95,8 +95,8 @@ const headers = [
const color = (type: string) => (type.includes('image') ? 'green' : type.includes('video') ? 'blue' : type.includes('pdf') ? 'yellow' : 'red');
const rows: ComputedRef<Field[]> = computed(() =>
sortedRessources.value.map(res => {
- const parent = res.parent_id ? useNodesStore().getById(res.parent_id) : null;
- const category = parent ? useNodesStore().getById(parent.parent_id || '') : null;
+ const parent = res.parent_id ? nodesStore.getById(res.parent_id) : null;
+ const category = parent ? nodesStore.getById(parent.parent_id || '') : null;
return {
name: { content: res.name, type: 'text' },
size: { content: readableFileSize(res.size ?? 0), type: 'text' },
diff --git a/frontend/app/pages/dashboard/docs/[id].vue b/frontend/app/pages/dashboard/docs/[id].vue
index accae416..9c50a8d8 100644
--- a/frontend/app/pages/dashboard/docs/[id].vue
+++ b/frontend/app/pages/dashboard/docs/[id].vue
@@ -74,8 +74,8 @@ definePageMeta({
},
});
-const next = computed(() => documentsStore.getNext(article.value));
-const previous = computed(() => documentsStore.getPrevious(article.value));
+const next = computed(() => useSidebarTree().structure.value.next(article.value?.id)?.data);
+const previous = computed(() => useSidebarTree().structure.value.previous(article.value?.id)?.data);
const width = computed(() => {
if (preferencesStore.get('docSize').value == 2) return '980px';
if (preferencesStore.get('docSize').value == 1) return '800px';
diff --git a/frontend/app/stores/collection.ts b/frontend/app/stores/collection.ts
index bc33c078..3cab24f8 100644
--- a/frontend/app/stores/collection.ts
+++ b/frontend/app/stores/collection.ts
@@ -116,10 +116,9 @@ export class Collection<K, V> extends Map<K, V> {
return this;
}
- public toArray(): Array<V> | null {
+ public toArray(): Array<V> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that: this = this;
- if (that == null) return that as null;
const newArray = [];
for (const [_, v] of that) {
newArray.push(v);
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index 87cfc25a..fa43cbda 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -14,7 +14,7 @@ interface SearchOptions {
export const useNodesStore = defineStore('nodes', {
state: () => ({
nodes: new Collection<string, Node>(),
- public_nodes: [] as Node[],
+ public_nodes: new Collection<string, Node>(),
allTags: [] as string[],
isFetching: false,
}),
@@ -41,16 +41,6 @@ export const useNodesStore = defineStore('nodes', {
};
return checkDescendants(node);
},
- getNext: state => (node?: Node) => {
- if (!node) return state.nodes.first();
- return state.nodes.next(node.id);
- },
-
- getPrevious: state => (node?: Node) => {
- if (!node) return state.nodes.last();
- return state.nodes.previous(node.id);
- },
-
getAllChildrens: state => (id: string) => {
const parent = state.nodes.find(d => d.id == id);
if (!parent) return [];
@@ -82,7 +72,7 @@ export const useNodesStore = defineStore('nodes', {
},
search: state => (options: SearchOptions) => {
const { query, fromDate, toDate, dateType, tags, category } = options;
- let filtered = state.nodes.toArray()!;
+ let filtered = state.nodes.toArray().filter(n => n.role === 3); // Only documents
if (query) {
filtered = filtered.filter(node => {
const nodeContent = `${node.name} ${node.description} ${node.tags}`.toLowerCase();
@@ -145,15 +135,14 @@ export const useNodesStore = defineStore('nodes', {
if (node.tags) {
parseTags(node.tags).forEach(tag => tags.add(tag));
}
- if (node.parent_id && !this.nodes.find(n => n.id === node.parent_id)) {
+ if (node.parent_id && !this.nodes.get(node.parent_id)) {
node.parent_id = '';
}
});
this.allTags = Array.from(tags).sort();
},
async fetch<T extends FetchOptions>(opts?: T): Promise<'id' extends keyof T ? Node : Collection<string, Node>> {
- if (opts?.id && this.nodes.find(d => d.id == opts.id && !d.partial))
- return this.nodes.find(d => d.id == opts.id) as 'id' extends keyof T ? Node : Collection<string, Node>;
+ if (opts?.id && !this.nodes.get(opts.id)?.partial) return this.nodes.get(opts.id) as 'id' extends keyof T ? Node : Collection<string, Node>;
console.log(`[store/nodes] Fetching nodes with options: ${JSON.stringify(opts)}`);
if (!this.nodes.size) this.isFetching = true;
const request = await makeRequest(`nodes/@me/${opts?.id || ''}`, 'GET', {});
@@ -181,12 +170,12 @@ export const useNodesStore = defineStore('nodes', {
},
async fetchPublic(id: string): Promise<Node | undefined> {
console.log(`[store/nodes] Fetching public nodeument with id: ${id}`);
- const existingDoc = this.public_nodes.find(d => d.id === id);
+ const existingDoc = this.public_nodes.get(id);
if (existingDoc) return existingDoc;
const request = await makeRequest(`nodes/public/${id}`, 'GET', {});
if (request.status === 'success') {
const fetchedDoc: Node = { ...(request.result as DB_Node), partial: false, shared: false, permissions: [] };
- this.public_nodes.push(fetchedDoc);
+ this.public_nodes.set(fetchedDoc.id, fetchedDoc);
return fetchedDoc;
} else return undefined;
},
@@ -208,7 +197,7 @@ export const useNodesStore = defineStore('nodes', {
async addPermission(perm: Omit<Permission, 'id' | 'created_timestamp'>): Promise<Permission> {
console.log(`[store/nodes/permissions] Adding permission for user ${perm.user_id} on node ${perm.node_id}`);
- const node = this.nodes.find(n => n.id === perm.node_id);
+ const node = this.nodes.get(perm.node_id);
if (!node) throw 'Node not found in store, cannot add permission';
const request = await makeRequest(`permissions`, 'POST', perm);
if (request.status === 'success') {
@@ -260,7 +249,7 @@ export const useNodesStore = defineStore('nodes', {
},
async delete(id: string) {
const request = await makeRequest(`nodes/${id}`, 'DELETE', {});
- if (request.status == 'success') return (this.nodes = this.nodes.filter(d => d.id != id));
+ if (request.status == 'success') return this.nodes.delete(id);
else throw request.message;
},
},
diff --git a/frontend/app/stores/resources.store.ts b/frontend/app/stores/resources.store.ts
index d5a65dc5..292d85b7 100644
--- a/frontend/app/stores/resources.store.ts
+++ b/frontend/app/stores/resources.store.ts
@@ -13,7 +13,7 @@ export const useRessourcesStore = defineStore('ressources', {
async post(ressource: FormData): Promise<Node> {
const request = await makeRequest(`ressources`, 'POST', ressource);
if (request.status == 'success') {
- useNodesStore().nodes.push(request.result as Node);
+ useNodesStore().nodes.set((request.result as Node).id, request.result as Node);
return request.result as Node;
} else throw request.message;
},
@@ -26,14 +26,13 @@ export const useRessourcesStore = defineStore('ressources', {
async update(ressource: Node): Promise<Node | string> {
const request = await makeRequest(`ressources/${ressource.id}`, 'PUT', ressource);
if (request.status == 'success') {
- const index = useNodesStore().nodes.findIndex(c => c.id == ressource.id);
- if (index != -1) useNodesStore().nodes[index] = ressource as Node;
+ useNodesStore().nodes.set(ressource.id, ressource as Node);
return request.result as Node;
} else throw request.message;
},
async delete(id: string) {
const request = await makeRequest(`ressources/${id}`, 'DELETE', {});
- if (request.status == 'success') return (useNodesStore().nodes = useNodesStore().nodes.filter(c => c.id != id));
+ if (request.status == 'success') return useNodesStore().nodes.delete(id);
else throw request.message;
},
},