π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Fix CDN, backend nodes, new structures
Smaug6739f004b47ad601
diff --git a/backend/controllers/nodes.controller.go b/backend/controllers/nodes.controller.goindex 95d0ae11..39cbeaa2 100644--- a/backend/controllers/nodes.controller.go+++ b/backend/controllers/nodes.controller.go@@ -166,7 +166,6 @@ func (ctr *Controller) UpdateNode(c *gin.Context) (int, any) {node = &models.Node{Id: nodeId,Name: node.Name,- Role: db_node.Role,Description: node.Description,Tags: node.Tags,Thumbnail: node.Thumbnail,@@ -179,8 +178,8 @@ func (ctr *Controller) UpdateNode(c *gin.Context) (int, any) {Order: node.Order,Content: node.Content,ContentCompiled: node.ContentCompiled,- UserId: db_node.UserId,- CreatedTimestamp: time.Now().UnixMilli(),+ Metadata: node.Metadata,+ UpdatedTimestamp: time.Now().UnixMilli(),}err = ctr.app.Services.Nodes.UpdateNode(node)diff --git a/backend/controllers/ressources.controller.go b/backend/controllers/ressources.controller.goindex 9e54a6ed..ec9ff7e5 100644--- a/backend/controllers/ressources.controller.go+++ b/backend/controllers/ressources.controller.go@@ -3,6 +3,7 @@ package controllersimport ("alexandrie/app""alexandrie/models"+ "alexandrie/types""alexandrie/utils""bytes""context"@@ -120,7 +121,7 @@ func (ctr *Controller) UploadFile(c *gin.Context) (int, any) {}id := ctr.app.Snowflake.Generate()transformedPath := fmt.Sprintf("%d%s", id, ext)- metadata := map[string]interface{}{+ metadata := types.JSONB{"filetype": mimeType,"original_path": header.Filename,"transformed_path": transformedPath,diff --git a/backend/models/node.model.go b/backend/models/node.model.goindex 47b821c7..96b2c052 100644--- a/backend/models/node.model.go+++ b/backend/models/node.model.go@@ -4,24 +4,24 @@ import "alexandrie/types"type Node struct {// Node- Id types.Snowflake `json:"id" form:"id" binding:"omitempty"`- UserId types.Snowflake `json:"user_id" form:"user_id" binding:"omitempty"`- ParentId *types.Snowflake `json:"parent_id" form:"parent_id" binding:"omitempty"`- Name string `json:"name" form:"name" binding:"required,max=50"`- Description *string `json:"description" form:"description" binding:"omitempty,max=250"`- Tags *string `json:"tags" form:"tags" binding:"omitempty,max=250"`- Role int `json:"role" form:"role" binding:"omitempty"`- Color *int `json:"color" form:"color" binding:"omitempty"`- Icon *string `json:"icon" form:"icon" binding:"omitempty"`- Thumbnail *string `json:"thumbnail" form:"thumbnail" binding:"omitempty"`- Theme *string `json:"theme" form:"theme" binding:"omitempty"`- Accessibility *int `json:"accessibility" form:"accessibility" binding:"omitempty"` // 0: Public; 1: Private; 2: Unlisted;- Display *int `json:"display" form:"display" binding:"omitempty"`- Order *int `json:"order" form:"order" binding:"omitempty"` // -1 for pinned and -2 for bookmark- Content *string `json:"content" form:"content"`- ContentCompiled *string `json:"content_compiled" form:"content_compiled"`- Size *int64 `json:"size" form:"size" binding:"omitempty"`- Metadata *map[string]interface{} `json:"metadata" form:"metadata"` // <- flexible JSON- CreatedTimestamp int64 `json:"created_timestamp" form:"created_timestamp" binding:"omitempty"`- UpdatedTimestamp int64 `json:"updated_timestamp" form:"updated_timestamp" binding:"omitempty"`+ Id types.Snowflake `json:"id" form:"id" binding:"omitempty"`+ UserId types.Snowflake `json:"user_id" form:"user_id" binding:"omitempty"`+ ParentId *types.Snowflake `json:"parent_id" form:"parent_id" binding:"omitempty"`+ Name string `json:"name" form:"name" binding:"required,max=50"`+ Description *string `json:"description" form:"description" binding:"omitempty,max=250"`+ Tags *string `json:"tags" form:"tags" binding:"omitempty,max=250"`+ Role int `json:"role" form:"role" binding:"omitempty"`+ Color *int `json:"color" form:"color" binding:"omitempty"`+ Icon *string `json:"icon" form:"icon" binding:"omitempty"`+ Thumbnail *string `json:"thumbnail" form:"thumbnail" binding:"omitempty"`+ Theme *string `json:"theme" form:"theme" binding:"omitempty"`+ Accessibility *int `json:"accessibility" form:"accessibility" binding:"omitempty"` // 0: Public; 1: Private; 2: Unlisted;+ Display *int `json:"display" form:"display" binding:"omitempty"`+ Order *int `json:"order" form:"order" binding:"omitempty"` // -1 for pinned and -2 for bookmark+ Content *string `json:"content" form:"content"`+ ContentCompiled *string `json:"content_compiled" form:"content_compiled"`+ Size *int64 `json:"size" form:"size" binding:"omitempty"`+ Metadata *types.JSONB `json:"metadata" form:"metadata"`+ CreatedTimestamp int64 `json:"created_timestamp" form:"created_timestamp" binding:"omitempty"`+ UpdatedTimestamp int64 `json:"updated_timestamp" form:"updated_timestamp" binding:"omitempty"`}diff --git a/backend/services/node.service.go b/backend/services/node.service.goindex 499b54f3..d74ce1ef 100644--- a/backend/services/node.service.go+++ b/backend/services/node.service.go@@ -23,7 +23,7 @@ func NewNodeService(db *sql.DB) NodeService {func (s *Service) GetAllNodes(userId types.Snowflake) ([]*models.Node, error) {var nodes = make([]*models.Node, 0)- rows, err := s.db.Query("SELECT `id`, `user_id`, `parent_id`, `name`, `description`, `tags`, `role`, `color`, `icon`, `theme`, `accessibility`, `display`, `order`, `created_timestamp`, `updated_timestamp` FROM nodes WHERE user_id = ? ORDER BY `order` DESC, name", userId)+ rows, err := s.db.Query("SELECT `id`, `user_id`, `parent_id`, `name`, `description`, `tags`, `role`, `color`, `icon`, `theme`, `accessibility`, `display`, `order`, `size`, `metadata`, `created_timestamp`, `updated_timestamp` FROM nodes WHERE user_id = ? ORDER BY `role`, `order` DESC, name", userId)if err != nil {return nil, err}@@ -45,6 +45,8 @@ func (s *Service) GetAllNodes(userId types.Snowflake) ([]*models.Node, error) {&node.Accessibility,&node.Display,&node.Order,+ &node.Size,+ &node.Metadata,&node.CreatedTimestamp,&node.UpdatedTimestamp,); err != nil {@@ -57,7 +59,7 @@ func (s *Service) GetAllNodes(userId types.Snowflake) ([]*models.Node, error) {func (s *Service) GetAllNodeBackup(user_id types.Snowflake) ([]*models.Node, error) {var nodes = make([]*models.Node, 0)- rows, err := s.db.Query("SELECT `id`, user_id, parent_id, name, description, tags, role, color, icon, thumbnail, theme, accessibility, display, order, content, content_compiled, size, metadata, created_timestamp, updated_timestamp FROM nodes WHERE user_id = ?", user_id)+ rows, err := s.db.Query("SELECT `id`, `user_id`, `parent_id`, `name`, `description`, `tags`, `role`, `color`, `icon`, `thumbnail`, `theme`, `accessibility`, `display`, `order`, `content`, `content_compiled`, `size`, `metadata`, `created_timestamp`, `updated_timestamp` FROM nodes WHERE user_id = ?", user_id)if err != nil {return nil, err}@@ -93,7 +95,7 @@ func (s *Service) GetAllNodeBackup(user_id types.Snowflake) ([]*models.Node, errfunc (s *Service) GetUserUploadsSize(userId types.Snowflake) (int64, error) {var totalSize *int64- err := s.db.QueryRow("SELECT SUM(file_size) FROM nodes WHERE user_id = ?", userId).Scan(&totalSize)+ err := s.db.QueryRow("SELECT SUM(size) FROM nodes WHERE user_id = ?", userId).Scan(&totalSize)if err != nil {return 0, err}@@ -187,12 +189,11 @@ func (s *Service) CreateNode(node *models.Node) error {}func (s *Service) UpdateNode(node *models.Node) error {- _, err := s.db.Exec("UPDATE nodes SET `parent_id` = ?, `name` = ?, `description` = ?, `tags` = ?, `role` = ?, `color` = ?, `icon` = ?, `thumbnail` = ?, `theme` = ?, `accessibility` = ?, `display` = ?, `order` = ?, `content` = ?, `content_compiled` = ?, `size` = ?, `metadata` = ?, `updated_timestamp` = ? WHERE id = ?",+ _, err := s.db.Exec("UPDATE nodes SET `parent_id` = ?, `name` = ?, `description` = ?, `tags` = ?, `color` = ?, `icon` = ?, `thumbnail` = ?, `theme` = ?, `accessibility` = ?, `display` = ?, `order` = ?, `content` = ?, `content_compiled` = ?, `metadata` = ?, `updated_timestamp` = ? WHERE id = ?",node.ParentId,node.Name,node.Description,node.Tags,- node.Role,node.Color,node.Icon,node.Thumbnail,@@ -202,7 +203,6 @@ func (s *Service) UpdateNode(node *models.Node) error {node.Order,node.Content,node.ContentCompiled,- node.Size,node.Metadata,node.UpdatedTimestamp,node.Id)diff --git a/backend/types/JSON.go b/backend/types/JSON.gonew file mode 100644index 00000000..9841bab8--- /dev/null+++ b/backend/types/JSON.go@@ -0,0 +1,30 @@+package types++import (+ "database/sql/driver"+ "encoding/json"+ "errors"+)++type JSONB map[string]interface{}++func (j *JSONB) Scan(value interface{}) error {+ if value == nil {+ *j = nil+ return nil+ }++ bytes, ok := value.([]byte)+ if !ok {+ return errors.New("invalid type for JSONB")+ }++ return json.Unmarshal(bytes, j)+}++func (j JSONB) Value() (driver.Value, error) {+ if j == nil {+ return nil, nil+ }+ return json.Marshal(j)+}diff --git a/frontend/app/composables/TreeStructure.ts b/frontend/app/composables/TreeStructure.tsindex dd0411a0..7e895b70 100644--- a/frontend/app/composables/TreeStructure.ts+++ b/frontend/app/composables/TreeStructure.ts@@ -28,7 +28,6 @@ export class TreeStructure {this.items = items;this.itemMap = new Map(items.map(item => [item.id, item]));this.childrenMap = new Map();-for (const item of items) {if (!this.childrenMap.has(item.parent_id || '')) this.childrenMap.set(item.parent_id || '', []);this.childrenMap.get(item.parent_id!)!.push(item);diff --git a/frontend/app/pages/dashboard/cdn/[id]/index.vue b/frontend/app/pages/dashboard/cdn/[id]/index.vueindex bbc502ca..eff46d02 100644--- a/frontend/app/pages/dashboard/cdn/[id]/index.vue+++ b/frontend/app/pages/dashboard/cdn/[id]/index.vue@@ -24,11 +24,11 @@<label>Original path</label><input id="content" type="text" :value="ressource.content" disabled /><label>Path</label>- <input id="path" type="text" :value="ressource.content_compiled" disabled />+ <input id="path" type="text" :value="ressource.metadata?.transformed_path" disabled /><p style="overflow-wrap: break-word">Ressource:- <a :href="`${CDN}/${ressource.user_id}/${ressource.content_compiled || ressource.content}`" target="_blank">{{- `${CDN}/${ressource.user_id}/${ressource.content_compiled || ressource.content}`+ <a :href="`${CDN}/${ressource.user_id}/${ressource.metadata?.transformed_path || ressource.content}`" target="_blank">{{+ `${CDN}/${ressource.user_id}/${ressource.metadata?.transformed_path || ressource.content}`}}</a></p><div style="display: flex; justify-content: flex-end">@@ -37,8 +37,8 @@<h4>Preview</h4><div class="preview"><img- v-if="(ressource.metadata?.filetype as string).startsWith('image/')"- :src="`${CDN}/${ressource.user_id}/${ressource.content_compiled || ressource.content}`"+ v-if="(ressource.metadata?.filetype as string)?.startsWith('image/')"+ :src="`${CDN}/${ressource.user_id}/${ressource.metadata?.transformed_path || ressource.content}`"alt="Preview"/><p v-else>Preview not available for this file type.</p>@@ -55,9 +55,9 @@<script lang="ts" setup>import DeleteRessourceModal from '../_modals/DeleteRessourceModal.vue';definePageMeta({ breadcrumb: 'Edit' });-const ressourcesStore = useRessourcesStore();+const nodeStore = useNodesStore();const route = useRoute();-const ressource = computed(() => ressourcesStore.getById(route.params.id as string));+const ressource = computed(() => nodeStore.getById(route.params.id as string));const defaultItem: ANode = {id: '',label: 'None',@@ -68,7 +68,7 @@ const tree = computed(() => [defaultItem, ...useSidebarTree().tree.value]);const updateCategory = async () => {if (ressource.value)- ressourcesStore+ nodeStore.update(ressource.value).then(() => {useNotifications().add({ type: 'success', title: 'Ressource updated' });diff --git a/frontend/app/pages/dashboard/cdn/[id]/preview.vue b/frontend/app/pages/dashboard/cdn/[id]/preview.vueindex f631ea81..36d7185a 100644--- a/frontend/app/pages/dashboard/cdn/[id]/preview.vue+++ b/frontend/app/pages/dashboard/cdn/[id]/preview.vue@@ -17,13 +17,13 @@</p><div class="preview"><img- v-if="(ressource?.metadata?.filetype as string).startsWith('image/')"- :src="`${CDN}/${ressource!.user_id}/${ressource!.content_compiled || ressource!.content}`"+ v-if="(ressource?.metadata?.filetype as string)?.startsWith('image/')"+ :src="`${CDN}/${ressource!.user_id}/${ressource!.metadata?.transformed_path || ressource!.content}`"alt="Preview"/><iframe- v-else-if="(ressource?.metadata?.filetype as string).startsWith('application/pdf')"- :src="`${CDN}/${ressource!.user_id}/${ressource!.content_compiled || ressource!.content}`"+ v-else-if="(ressource?.metadata?.filetype as string)?.startsWith('application/pdf')"+ :src="`${CDN}/${ressource!.user_id}/${ressource!.metadata?.transformed_path || ressource!.content}`"width="100%"height="500px"frameborder="0"@@ -37,10 +37,10 @@<script setup lang="ts">definePageMeta({ breadcrumb: 'Preview' });-const ressource = computed(() => useRessourcesStore().getById(useRoute().params.id as string));+const ressource = computed(() => useNodesStore().getById(useRoute().params.id as string));const copyLink = () => {- const link = `${CDN}/${ressource.value?.user_id}/${ressource.value?.content_compiled || ressource.value?.content}`;+ const link = `${CDN}/${ressource.value?.user_id}/${ressource.value?.metadata?.transformed_path || ressource.value?.content}`;navigator.clipboard.writeText(link);};</script>diff --git a/frontend/app/pages/dashboard/cdn/index.vue b/frontend/app/pages/dashboard/cdn/index.vueindex 046dd4f2..bf7f3439 100644--- a/frontend/app/pages/dashboard/cdn/index.vue+++ b/frontend/app/pages/dashboard/cdn/index.vue@@ -13,7 +13,7 @@<input v-model="fileLink" type="text" readonly /><AppButton type="primary" @click="copyLink">Copy link</AppButton></div>- <div v-if="ressourcesStore.ressources.length" class="ressources-list">+ <div v-if="sortedRessources.length" class="ressources-list"><DataTable v-if="view === 'table'" :headers="headers" :rows="rows"><template #action="{ cell }"><NuxtLink :href="`/dashboard/cdn/${(cell?.data as Node).id}/preview`" style="margin-right: 10px"><Icon name="view" /> </NuxtLink>@@ -23,7 +23,7 @@</DataTable><div v-else><div class="images-grid">- <div v-for="image in ressourcesStore.ressources" :key="image.id" class="image-item" @click="router.push(`/dashboard/cdn/${image.id}/preview`)">+ <div v-for="image in sortedRessources" :key="image.id" class="image-item" @click="router.push(`/dashboard/cdn/${image.id}/preview`)"><img :src="fileURL(image)" :alt="image.name" class="image-preview" /><div class="image-info"><span class="image-name">{{ image.name }}</span>@@ -43,6 +43,7 @@ import type { Node } from '~/stores';definePageMeta({ breadcrumb: 'Upload' });const router = useRouter();const ressourcesStore = useRessourcesStore();+const nodesStore = useNodesStore();const view = ref<'table' | 'list'>('list');const selectedFile: Ref<File | undefined> = ref();const fileLink = ref('');@@ -60,13 +61,15 @@ const submitFile = async () => {dropComponent.value.reset(); // Reset drop componentawait ressourcesStore.post(body)- .then(r => (fileLink.value = `${CDN}/${(r as Node).user_id}/${(r as Node).content_compiled}`))+ .then(r => (fileLink.value = `${CDN}/${(r as Node).user_id}/${(r as Node).metadata?.transformed_path as string}`)).catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e })).finally(() => (isLoading.value = false));};+const sortedRessources = computed(() => [...nodesStore.ressources].sort((a, b) => b.created_timestamp - a.created_timestamp));+const fileURL = (ressource: Node) => {- if ((ressource.metadata!.filetype as string).includes('image/')) return `${CDN}/${ressource.user_id}/${ressource.content_compiled}`;+ if ((ressource.metadata?.filetype as string)?.includes('image/')) return `${CDN}/${ressource.user_id}/${ressource.metadata?.transformed_path as string}`;return '/file_placeholder.png';};const headers = [@@ -79,13 +82,13 @@ const headers = [];const color = (type: string) => (type.includes('image') ? 'green' : type.includes('video') ? 'blue' : type.includes('pdf') ? 'yellow' : 'red');const rows: ComputedRef<Field[]> = computed(() =>- ressourcesStore.ressources.map(res => {+ sortedRessources.value.map(res => {const parent = res.parent_id ? useNodesStore().getById(res.parent_id) : null;const category = parent ? useNodesStore().getById(parent.parent_id || '') : null;return {name: { content: res.name, type: 'text' },size: { content: readableFileSize(res.size ?? 0), type: 'text' },- type: { content: `<tag class="${color(res.metadata!.filetype as string)}">${res.metadata!.filetype as string}</tag>`, type: 'html' },+ type: { content: `<tag class="${color(res.metadata?.filetype as string)}">${res.metadata?.filetype as string}</tag>`, type: 'html' },parent: { content: category ? `<tag class="${getAppColor(category.color)}">${parent?.name}</tag>` : '', type: 'html' },date: { content: new Date(res.created_timestamp).toLocaleDateString(), type: 'text' },action: { type: 'slot', data: res },diff --git a/frontend/app/pages/dashboard/docs/new.vue b/frontend/app/pages/dashboard/docs/new.vueindex f00c2bad..22b2407f 100644--- a/frontend/app/pages/dashboard/docs/new.vue+++ b/frontend/app/pages/dashboard/docs/new.vue@@ -9,6 +9,7 @@ const store = useNodesStore();const document = ref<Partial<Node>>({parent_id: (useRoute().query.cat as string | undefined) || useSidebar().workspaceId.value || undefined,accessibility: 1,+ role: 3,});const notifications = useNotifications();diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.tsindex 214936ad..f62b470a 100644--- a/frontend/app/stores/db_strustures.d.ts+++ b/frontend/app/stores/db_strustures.d.ts@@ -17,6 +17,32 @@ export interface DB_Node {content_compiled?: string;size?: number; // in bytesmetadata?: Record<string, unknown>;+ created_timestamp: number;+ updated_timestamp: number;+}+export interface DB_Node {+ id: string;+ user_id: string;+ parent_id?: string;+ name: string;+ description?: string;+ tags?: string;+ role: 4; // 1: Workspace; 2: Category; 3: Document; 4: Ressource+ color?: number; // -1: Default; 0: None; 1-7: App colors+ icon?: string;+ thumbnail?: string;+ theme?: string;+ accessibility?: number; // 1 Visible; 2 Draft; 3 Archived;+ display?: number; // 1 List; 2 Grid;+ order?: number; // -1 for pinned and -2 for bookmark+ content?: string;+ content_compiled?: string;+ size?: number; // in bytes+ metadata?: {+ filetype?: string;+ original_path?: string;+ transformed_path?: string;+ };created_timestamp: string;updated_timestamp: string;}diff --git a/frontend/app/stores/documents.store.ts b/frontend/app/stores/documents.store.tsindex 4bde6c24..8679cf88 100644--- a/frontend/app/stores/documents.store.ts+++ b/frontend/app/stores/documents.store.ts@@ -24,6 +24,9 @@ export const useNodesStore = defineStore('nodes', {getByCategories: state => (category: string) => state.nodes.filter(d => d.parent_id == category),getParents: state => state.nodes.filter(c => !c.parent_id),getChilds: state => (id: string) => state.nodes.filter(c => c.parent_id == id),+ categories: state => state.nodes.filter(d => d.role === 1 || d.role === 2),+ documents: state => state.nodes.filter(d => d.role === 3),+ ressources: state => state.nodes.filter(d => d.role === 4),getNext: state => (node?: Node) => {const cnodes = state.nodes.filter(d => d.parent_id == node?.parent_id);@@ -140,12 +143,15 @@ export const useNodesStore = defineStore('nodes', {},async update(node: Node) {+ console.log(node);if (node.partial) {console.log('[store/nodes] Node is partial, cannot update it directly.');- const fullDoc = await this.fetch({ id: node.id });- if (!fullDoc) throw 'Node not found';- node = { ...fullDoc, ...node, partial: false }; // Merge with full nodeument data+ const full_node = await this.fetch({ id: node.id });+ if (!full_node) throw 'Node not found';+ console.log(full_node);+ node = { ...full_node, ...node, partial: false }; // Merge with full nodeument data}+ console.log(node);const request = await makeRequest(`nodes/${node.id}`, 'PUT', node);if (request.status == 'success') return (this.nodes = this.nodes.map(d => (d.id == node.id ? node : d)));else throw request.message;diff --git a/frontend/app/stores/resources.store.ts b/frontend/app/stores/resources.store.tsindex fc89739f..d5a65dc5 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') {- this.ressources.push(request.result as Node);+ useNodesStore().nodes.push(request.result as Node);return request.result as Node;} else throw request.message;},@@ -26,14 +26,14 @@ 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 = this.ressources.findIndex(c => c.id == ressource.id);- if (index != -1) this.ressources[index] = ressource as Node;+ const index = useNodesStore().nodes.findIndex(c => c.id == ressource.id);+ if (index != -1) useNodesStore().nodes[index] = 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 (this.ressources = this.ressources.filter(c => c.id != id));+ if (request.status == 'success') return (useNodesStore().nodes = useNodesStore().nodes.filter(c => c.id != id));else throw request.message;},},