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.

New settings page, navigation system, new backup system, refactored sidebar header UI, improved theme, user store & last_connection, new backend CDN, new icons composable system, avatar system, updated user system.

Smaug67396aa722207b42
diff --git a/.gitignore b/.gitignore
index 554aeef6..565b4547 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,13 @@ uploads/images/*
uploads/webp/*
uploads/backups/*
uploads/other/*
+uploads/avatars/images/*
+uploads/avatars/webp/*
!uploads/images/.gitkeep
!uploads/webp/.gitkeep
!uploads/backups/.gitkeep
-!uploads/other/.gitkeep
\ No newline at end of file
+!uploads/other/.gitkeep
+!uploads/avatars/images/.gitkeep
+!uploads/avatars/webp/.gitkeep
+!uploads/avatars/webp/default.svg
+!uploads/webp/default.svg
diff --git a/backend/App.ts b/backend/App.ts
index be825b90..e310d2ba 100644
--- a/backend/App.ts
+++ b/backend/App.ts
@@ -72,6 +72,7 @@ export class App {
redirect: false,
setHeaders: function (res: Response) {
res.set('x-timestamp', Date.now().toString());
+ if (res.req.url.startsWith('/backups')) res.setHeader('Content-Disposition', `attachment; filename`);
},
};
this.app.use('/static', express.static(this.config.upload_path, staticOptions));
diff --git a/backend/bun.lockb b/backend/bun.lockb
index 99302c68..0a03e566 100755
Binary files a/backend/bun.lockb and b/backend/bun.lockb differ
diff --git a/backend/classes/BackupManager.ts b/backend/classes/BackupManager.ts
new file mode 100644
index 00000000..2535a984
--- /dev/null
+++ b/backend/classes/BackupManager.ts
@@ -0,0 +1,22 @@
+import Base from './Base';
+import { JsonStreamStringify } from 'json-stream-stringify';
+import { createWriteStream } from 'fs';
+import { Validator } from './Validator';
+
+export class BackupManager extends Base {
+ constructor(app: App) {
+ super(app);
+ }
+
+ public validator = new Validator({});
+
+ public saveBackup(user_id: string, file_path: string) {
+ return new Promise((resolve, reject) => {
+ const stream = this.app.db.query('SELECT * from `documents` WHERE `author_id` = ?', [user_id]).stream();
+ const writeStream = createWriteStream(file_path);
+ new JsonStreamStringify(stream).pipe(writeStream).on('error', (err: Error) => reject(err));
+
+ writeStream.on('finish', () => resolve(file_path));
+ });
+ }
+}
diff --git a/backend/classes/index.ts b/backend/classes/index.ts
index 61a82fae..edd8ce98 100644
--- a/backend/classes/index.ts
+++ b/backend/classes/index.ts
@@ -1,3 +1,4 @@
+export * from './BackupManager';
export * from './CategoriesManager';
export * from './ConnectionsLogsManager';
export * from './SessionsManager';
diff --git a/backend/controllers/backups.controller.ts b/backend/controllers/backups.controller.ts
index a2417cd6..3fa0cc9c 100644
--- a/backend/controllers/backups.controller.ts
+++ b/backend/controllers/backups.controller.ts
@@ -1,41 +1,45 @@
-import { createWriteStream, unlinkSync, readdirSync } from 'fs';
-import { spawn } from 'child_process';
-import { error, success } from '../utils/functions';
+import * as fs from 'fs/promises';
+import * as path from 'path';
import type { Request, Response } from 'express';
+import BaseController from './BaseController';
+import { BackupManager } from '../classes';
-export default class BackupController {
- app: App;
- constructor(app: App) {
+export default class BackupController extends BaseController<any> {
+ constructor(app: any) {
+ super(new BackupManager(app));
this.app = app;
}
- async add(_: Request, res: Response) {
- // Clean the uploads directory
- const files = readdirSync(this.app.config.upload_path + '/backups');
- for (const file of files) {
- if (file.endsWith('.sql')) unlinkSync(`${this.app.config.upload_path}/backups/${file}`);
- }
- const name = `backup-${new Date().toISOString().split('T')[0]}-${Date.now()}`;
- const mysqldump = spawn('mysqldump', [
- '-u',
- `${process.env.DATABASE_USER}`,
- `-p${process.env.DATABASE_PASSWORD}`,
- 'alexandrie',
- ]);
+ async add(req: Request, res: Response) {
+ const userId = req.user_id;
+ if (!userId) return res.status(401).send({ message: 'Unauthorized' });
+ const date = new Date().toISOString().split('T')[0];
+ const timestamp = Date.now();
+ const name = `backup-${date}-${timestamp}.json`;
+
+ const backupDir = path.join(this.app.config.upload_path, 'backups', userId);
+ const backupFile = path.join(backupDir, name);
- const wstream = createWriteStream(`${this.app.config.upload_path}/backups/${name}.sql`);
- const backupPromise = new Promise<void | string>((resolve, reject) => {
- mysqldump.stdout
- .pipe(wstream)
- .on('finish', function () {
- resolve();
- })
- .on('error', function (err) {
- reject(err.message);
- });
- });
- backupPromise
- .then(() => res.json(success({ url: `/backups/${name}.sql` })))
- .catch((err: Error) => res.json(error(err.message)));
+ try {
+ // Check if the directory exists
+ try {
+ await fs.access(backupDir);
+ // If directory exists, clean it
+ const files = await fs.readdir(backupDir);
+ await Promise.all(files.map(file => fs.unlink(path.join(backupDir, file))));
+ } catch (error: any) {
+ if (error.code === 'ENOENT') {
+ // If directory does not exist, create it
+ await fs.mkdir(backupDir, { recursive: true });
+ } else {
+ throw error;
+ }
+ }
+
+ await this.manager.saveBackup(userId, backupFile);
+ res.status(201).json(this.utils.success({ url: `/backups/${req.user_id}/${name}` }));
+ } catch (err) {
+ res.status(500).json(this.utils.error(err));
+ }
}
}
diff --git a/backend/package.json b/backend/package.json
index 12649a40..22214e0c 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -20,23 +20,24 @@
},
"homepage": "https://github.com/Smaug6739/docs#readme",
"devDependencies": {
- "@types/bcrypt": "^5.0.0",
- "@types/bun": "^1.0.12",
- "@types/express": "^4.17.11",
- "@types/jsonwebtoken": "^9.0.3",
- "@types/multer": "^1.4.7",
+ "@types/bcrypt": "^5.0.2",
+ "@types/bun": "^1.1.6",
+ "@types/express": "^4.17.21",
+ "@types/jsonwebtoken": "^9.0.6",
+ "@types/multer": "^1.4.11",
"morgan": "^1.10.0",
- "nodemon": "^3.0.1",
- "typescript": "^5.2.2"
+ "nodemon": "^3.1.4",
+ "typescript": "^5.5.3"
},
"dependencies": {
- "bcrypt": "^5.0.1",
- "dotenv": "^16.3.1",
- "express": "^4.17.1",
+ "bcrypt": "^5.1.1",
+ "dotenv": "^16.4.5",
+ "express": "^4.19.2",
+ "json-stream-stringify": "^3.1.4",
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
- "mysql2": "^3.6.1",
- "sharp": "^0.33.3",
- "tslib": "^2.6.2"
+ "mysql2": "^3.10.3",
+ "sharp": "^0.33.4",
+ "tslib": "^2.6.3"
}
}
diff --git a/frontend/components/Icon.vue b/frontend/components/Icon.vue
new file mode 100644
index 00000000..2fd4eaa4
--- /dev/null
+++ b/frontend/components/Icon.vue
@@ -0,0 +1,39 @@
+<template>
+ <i v-html="icon" class="icon" :style="{ fill: props.fill || 'var(--red)' }"
+ :class="{ fill: props.fill, big: props.big }"></i>
+</template>
+
+<script setup lang="ts">
+import type { IconName } from '~/composables/icons';
+const props = defineProps<{ name: IconName | string, fill?: string, big?: true }>();
+const icon = useIcon(props.name as IconName) || props.name;
+
+</script>
+
+<style scoped lang="scss">
+.icon {
+ display: flex;
+ align-items: center;
+
+ &:deep(svg) {
+ width: 20px;
+ max-height: 22px;
+ margin-right: 5px;
+
+ path {
+ fill: inherit; // Utilise la couleur de l'élément parent }
+ }
+ }
+}
+
+.fill:deep(svg)>path {
+ fill: inherit !important; // Utilise la couleur de l'élément parent }
+}
+
+.big {
+ &:deep(svg) {
+ width: 30px;
+ max-height: 30px;
+ }
+}
+</style>
\ No newline at end of file
diff --git a/frontend/components/MarkdownEditor/LazyToolbar.vue b/frontend/components/MarkdownEditor/LazyToolbar.vue
index a4e98a32..a10d765f 100644
--- a/frontend/components/MarkdownEditor/LazyToolbar.vue
+++ b/frontend/components/MarkdownEditor/LazyToolbar.vue
@@ -3,9 +3,9 @@
<button v-for="item in toolbar" :key="item.name" v-html="item.icon" class="btn"
@click="emitAction(item.action)"></button>
<select v-model="copy.accessibility" style="margin-right:5px;">
- <option value="1">Visible</option>
- <option value="2">Draf</option>
- <option value="3">Archive</option>
+ <option :value="1">Visible</option>
+ <option :value="2">Draf</option>
+ <option :value="3">Archive</option>
</select>
<select v-model="copy.category" style="margin-right:5px;">
<optgroup v-for="cat in categoriesStore.getParents" :label="cat.name" :key="cat.id">
diff --git a/frontend/components/Modal.vue b/frontend/components/Modal.vue
index f3e40676..a069577e 100644
--- a/frontend/components/Modal.vue
+++ b/frontend/components/Modal.vue
@@ -1,12 +1,12 @@
<script setup lang="ts">
-defineProps<{ show: boolean, size?: 'large' }>()
+defineProps<{ show: boolean }>()
const emit = defineEmits(['close', 'confirm'])
</script>
<template>
<Transition name="modal">
<div v-if="show" class="modal-mask">
- <div class="modal-container" :class="size">
+ <div class="modal-container">
<slot></slot>
</div>
</div>
@@ -43,13 +43,6 @@ const emit = defineEmits(['close', 'confirm'])
opacity: 0;
}
-.large {
- width: 1150px;
- height: calc(-100px + 100vh);
- max-width: calc(-100px + 100vw);
- max-height: 715px;
-}
-
.modal-enter-from .modal-container,
.modal-leave-to .modal-container {
-webkit-transform: scale(1.1);
diff --git a/frontend/components/Sidebar/CollapseItem.vue b/frontend/components/Sidebar/CollapseItem.vue
index 26fb3f5c..9a258694 100644
--- a/frontend/components/Sidebar/CollapseItem.vue
+++ b/frontend/components/Sidebar/CollapseItem.vue
@@ -23,7 +23,7 @@
<SidebarItem v-else :item="item" />
</template>
<script setup lang="ts">
-import { type Item } from './tree_builder';
+import type { Item } from './tree_builder';
import SidebarItem from './SidebarItem.vue';
defineProps<{ item: Item, root?: boolean }>();
diff --git a/frontend/components/Sidebar/Search.vue b/frontend/components/Sidebar/Search.vue
index c8f6c396..06394440 100644
--- a/frontend/components/Sidebar/Search.vue
+++ b/frontend/components/Sidebar/Search.vue
@@ -9,12 +9,8 @@
<path d="m21 21-4.3-4.3"></path>
</svg>
<input type="text" v-model="filter" placeholder="Search document" ref="searchInput" />
- <button @click="close"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
- fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
- class="h-4 w-4">
- <path d="M18 6 6 18"></path>
- <path d="m6 6 12 12"></path>
- </svg>
+ <button @click="close" style="background: none;">
+ <Icon name="close" />
</button>
</span>
<span class="title">Documents</span>
diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vue
index f3cd161f..534e3966 100644
--- a/frontend/components/Sidebar/Sidebar.vue
+++ b/frontend/components/Sidebar/Sidebar.vue
@@ -1,19 +1,27 @@
<template>
- <div :class="{ 'modal-mask': isMobile() && isOpened }"></div>
- <Resizable>
- <div class="sidebar-content">
- <section class="header">
- <span class="name">
- <IconApp />
- <NuxtLink style="font-size: 19px;font-weight: 600;" to="/">Alexandrie</NuxtLink>
- </span>
- <IconClose class="btn" />
- </section>
- <input type="text" placeholder="Search or Ctrl + q" class="search" v-model="filter" />
- <Search />
- <CollapseItem v-for="(item, index) in items " :key="index" :item="item" :root="true" />
- </div>
- </Resizable>
+ <div :class="{ 'modal-mask': isMobile() && isOpened }"></div>
+ <Resizable>
+ <div class="sidebar-content">
+ <section class="header">
+ <span class="name">
+ <IconApp />
+ <NuxtLink style="font-size: 19px; font-weight: 600" to="/">Alexandrie</NuxtLink>
+ </span>
+ <IconClose class="btn" />
+ </section>
+ <input type="text" placeholder="Search or Ctrl + q" class="search" v-model="filter" />
+
+ <div class="user" v-if="usrStr.user">
+ <img :src="useAvatar(usrStr.user)" alt="Avatar" style="width: 25px; height: 25px; border-radius: 50%" />
+ <div>
+ <div class="username">{{ usrStr.user.username }}</div>
+ <div class="email">{{ usrStr.user.email }}</div>
+ </div>
+ </div>
+ <Search />
+ <CollapseItem v-for="(item, index) in items" :key="index" :item="item" :root="true" />
+ </div>
+ </Resizable>
</template>
<script setup lang="ts">
@@ -22,99 +30,113 @@ import Resizable from './Resizable.vue';
import IconClose from './IconClose.vue';
import IconApp from './IconApp.vue';
import Search from './Search.vue';
-import { useCategoriesStore, useDocumentsStore, type Category } from '~/stores';
+import { useCategoriesStore, useDocumentsStore, useUserStore, type Category } from '~/stores';
import { ItemsManager, type Item } from './tree_builder';
-import { navigationItems } from "./helpers";
-
+import { navigationItems } from './helpers';
const { isOpened, hasSidebar } = useSidebar();
const categoriesStore = useCategoriesStore();
const documentsStore = useDocumentsStore();
+const usrStr = useUserStore();
const filter = ref<string>('');
const showSearchModal = ref<boolean>(false);
const handleSearchShortCut = (e: KeyboardEvent) => {
- if (e.ctrlKey && e.key === 'q') showSearchModal.value = !showSearchModal.value;
+ if (e.ctrlKey && e.key === 'q') showSearchModal.value = !showSearchModal.value;
};
const items = computed((): Item[] => {
- const navigation: Item[] = navigationItems.map((item) => ({ id: item.id, parent_id: '', title: item.title, route: item.route, icon: item.icon, type: 'navigation', data: item }))
- const categories: Item[] = categoriesStore.categories.map((category: Category) => ({
- id: category.id,
- parent_id: category.parent_id || '',
- title: category.name,
- route: category.parent_id ? `/dashboard/categories/${category.id}` : '',
- icon: category.icon,
- data: category,
- }))
- const documents: Item[] = documentsStore.documents.map((document) => ({
- id: document.id,
- parent_id: document.parent_id || document.category || '',
- title: document.name,
- route: `/dashboard/docs/${document.id}`,
- data: document
- })).filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));
+ const navigation: Item[] = navigationItems.map(item => ({ id: item.id, parent_id: '', title: item.title, route: item.route, icon: item.icon, type: 'navigation', data: item }));
+ const categories: Item[] = categoriesStore.categories.map((category: Category) => ({
+ id: category.id,
+ parent_id: category.parent_id || '',
+ title: category.name,
+ route: category.parent_id ? `/dashboard/categories/${category.id}` : '',
+ icon: category.icon,
+ data: category,
+ }));
+ const documents: Item[] = documentsStore.documents
+ .map(document => ({
+ id: document.id,
+ parent_id: document.parent_id || document.category || '',
+ title: document.name,
+ route: `/dashboard/docs/${document.id}`,
+ data: document,
+ }))
+ .filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));
- if (filter.value) return new ItemsManager([...navigation, ...documents]).generateTree();
- return new ItemsManager([...navigation, ...documents, ...categories]).generateTree();
+ if (filter.value) return new ItemsManager([...navigation, ...documents]).generateTree();
+ return new ItemsManager([...navigation, ...documents, ...categories]).generateTree();
});
-
const handleClickOutside = (e: MouseEvent) => {
- if (isOpened.value && e.target && (!(e.target as Element).closest('.sidebar') && !(e.target as Element).closest('.open-sidebar'))) isOpened.value = false;
+ if (isOpened.value && e.target && !(e.target as Element).closest('.sidebar') && !(e.target as Element).closest('.open-sidebar')) isOpened.value = false;
};
onMounted(() => {
- hasSidebar.value = true;
- if (isMobile()) return window.addEventListener('click', handleClickOutside);
- // ELSE: Desktop
- isOpened.value = true;
- document.addEventListener('keypress', handleSearchShortCut)
+ hasSidebar.value = true;
+ if (isMobile()) return window.addEventListener('click', handleClickOutside);
+ // ELSE: Desktop
+ isOpened.value = true;
+ document.addEventListener('keypress', handleSearchShortCut);
});
onBeforeUnmount(() => {
- hasSidebar.value = false;
- window.removeEventListener('click', handleClickOutside);
- document.removeEventListener('keypress', handleSearchShortCut)
+ hasSidebar.value = false;
+ window.removeEventListener('click', handleClickOutside);
+ document.removeEventListener('keypress', handleSearchShortCut);
});
</script>
<style scoped lang="scss">
.sidebar-content {
- margin: 0 0 0 10px;
+ margin: 0 0 0 10px;
}
.header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 50px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ height: 50px;
- .btn {
- fill: var(--font-color);
- width: 30px;
- cursor: pointer;
- }
+ .btn {
+ fill: var(--font-color);
+ width: 30px;
+ cursor: pointer;
+ }
- .name {
- display: flex;
- align-items: center;
- font-size: 1rem;
- font-weight: 400;
- font-family: Inter;
- }
+ .name {
+ display: flex;
+ align-items: center;
+ font-size: 1rem;
+ font-weight: 400;
+ font-family: Inter;
+ }
}
.search {
- height: 30px;
- margin: 2.5px 0;
- border-radius: 8px;
- width: 98%;
- outline: none;
- border: none;
- background-color: var(--bg-contrast);
- background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="%232573cf" height="24" viewBox="0 -960 960 960" width="22"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>');
- background-repeat: no-repeat;
- background-position: 5px;
- padding-left: 30px;
+ height: 30px;
+ margin: 2.5px 0;
+ border-radius: 8px;
+ width: 98%;
+ outline: none;
+ border: none;
+ background-color: var(--bg-contrast);
+ background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="%232573cf" height="24" viewBox="0 -960 960 960" width="22"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>');
+ background-repeat: no-repeat;
+ background-position: 5px;
+ padding-left: 30px;
+}
+.user {
+ display: flex;
+ align-items: center;
+ margin-top: 4px;
+ div {
+ font-size: 0.8rem;
+ margin-left: 5px;
+ .email {
+ font-size: 0.7rem;
+ color: var(--font-color-light);
+ }
+ }
}
-</style>
\ No newline at end of file
+</style>
diff --git a/frontend/components/Sidebar/SidebarItem.vue b/frontend/components/Sidebar/SidebarItem.vue
index b72d8312..597c88a3 100644
--- a/frontend/components/Sidebar/SidebarItem.vue
+++ b/frontend/components/Sidebar/SidebarItem.vue
@@ -1,38 +1,38 @@
<template>
- <NuxtLink class="item" :to="item.route" @click="() => item.route && toggle()" :draggable="draggable"
- @dragstart="dragStart" @dragover.prevent="dragOver" @drop="drop" @dragleave="dragLeave"
- :class="{ 'drag-over': isDragOver }">
- <i v-html="getIcon(item)" class="icon"></i>
+ <NuxtLink class="item" :to="item.route" @click="onClick" :draggable="draggable" @dragstart="dragStart"
+ @dragover.prevent="dragOver" @drop="drop" @dragleave="dragLeave" :class="{ 'drag-over': isDragOver }">
+ <Icon :name="getIcon(item)" />
<span>{{ item.title }}</span>
<slot></slot>
</NuxtLink>
</template>
<script setup lang="ts">
-
import { useDocumentsStore, useCategoriesStore } from '~/stores';
const documentStore = useDocumentsStore();
const categoriesStore = useCategoriesStore();
import type { Item } from './tree_builder';
-import { icons, navigationItems } from './helpers';
+import { navigationItems } from './helpers';
const { isOpened } = useSidebar();
const props = defineProps<{ item: Item }>();
function getIcon(item: Item) {
if ('icon' in item.data && item.data.icon) return item.data.icon;
- if (item.data.type === 'category') return icons.folder;
- if (item.data.type === 'document' && item.childrens?.length) return icons.file_parent;
- if (item.data.type === 'document' && item.data.accessibility == 2) return icons.draft;
- if (item.data.type === 'document' && item.data.accessibility == 3) return icons.archive;
- return icons.file;
+ if (item.data.type === 'category') return 'folder';
+ if (item.data.type === 'document' && item.childrens?.length) return 'file_parent';
+ if (item.data.type === 'document' && item.data.accessibility == 2) return 'draft';
+ if (item.data.type === 'document' && item.data.accessibility == 3) return 'archive';
+ return 'file';
}
-const toggle = () => isMobile() && (isOpened.value = false);
-
const draggable = ref<boolean>(true);
const isDragOver = ref<boolean>(false);
+const onClick = () => {
+ if (isMobile()) isOpened.value = false;
+};
+
const dragStart = (event: DragEvent) => {
// Stocke l'ID de l'élément en cours de glissement
event.dataTransfer!.setData('text/plain', props.item.id.toString());
diff --git a/frontend/components/Sidebar/helpers.ts b/frontend/components/Sidebar/helpers.ts
index cb761c0a..b050ccb9 100644
--- a/frontend/components/Sidebar/helpers.ts
+++ b/frontend/components/Sidebar/helpers.ts
@@ -8,19 +8,11 @@ export interface DefaultItem {
}
export const navigationItems: DefaultItem[] = [
- /*{
- id: 'search',
- type: 'default',
- title: 'Search',
- icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>',
- route: '/dashboard/search',
- childrens: [],
- },*/
{
id: 'manage-categories',
type: 'default',
title: 'Manage categories',
- icon: '<svg style="fill:var(--blue)" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h480v-480h-80v280l-100-60-100 60v-280H320v480Zm0 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm360-720h200-200Zm-200 0h480-480Z"/></svg>',
+ icon: 'categories',
route: '/dashboard/categories',
childrens: [],
},
@@ -28,41 +20,17 @@ export const navigationItems: DefaultItem[] = [
id: 'cdn',
type: 'default',
title: 'CDN',
- icon: '<svg style="fill:var(--blue)" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M485-440h163q26 0 44-18t18-44q0-26-18-44.5T648-565h-2q-5-32-29-53.5T560-640q-26 0-47 13.5T481-590q-30 2-50.5 23.5T410-515q0 30 21.5 52.5T485-440ZM120-120q-33 0-56.5-23.5T40-200v-520h80v520h680v80H120Zm160-160q-33 0-56.5-23.5T200-360v-440q0-33 23.5-56.5T280-880h200l80 80h280q33 0 56.5 23.5T920-720v360q0 33-23.5 56.5T840-280H280Zm0-80h560v-360H527l-80-80H280v440Zm0 0v-440 440Z"/></svg>',
+ icon: 'cdn',
route: '/dashboard/cdn',
childrens: [],
},
+
{
- id: 'backup',
- type: 'default',
- title: 'Backup',
- icon: '<svg style="fill:var(--blue)" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h200v-200H320v200Zm0-280h480v-200H320v200Zm280 280h200v-200H600v200Zm-280 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Z"/></svg>',
- route: '/dashboard/backup',
- childrens: [],
- },
- {
- id: 'new-page',
+ id: 'settings',
type: 'default',
- title: 'New page',
- icon: '<svg style="fill:var(--blue)" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-280h80v-160h160v-80H520v-160h-80v160H280v80h160v160ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>',
- route: '/dashboard/docs/new',
+ title: 'Settings',
+ icon: 'settings',
+ route: '/dashboard/settings',
childrens: [],
},
];
-export const icons = {
- draft:
- '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--turquoise)" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',
- folder:
- '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--yellow);" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>',
- file: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--red);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',
- file_parent:
- '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24" ><path style="fill:var(--green);" d="M320-320h200v-200H320v200Zm0-280h480v-200H320v200Zm280 280h200v-200H600v200Zm-280 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Z"/></svg>',
- archive:
- '<svg style="width:22px;height: 22px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none">\n' +
- '<rect x="2.5" y="2.5" width="11" height="11" rx="1.5" fill="var(--grey-bg)" stroke="var(--grey)"/>\n' +
- '<rect x="6" y="4" width="2" height="2" rx="0.5" fill="var(--grey)"/>\n' +
- '<rect x="6" y="8" width="2" height="2" rx="0.5" fill="var(--grey)"/>\n' +
- '<rect x="8" y="10" width="2" height="2" rx="0.5" fill="var(--grey)"/>\n' +
- '<rect x="8" y="6" width="2" height="2" rx="0.5" fill="var(--grey)"/>\n' +
- '</svg>',
-};
diff --git a/frontend/components/ThemeToggle.vue b/frontend/components/ThemeToggle.vue
index 9aca60e5..03c7cc17 100644
--- a/frontend/components/ThemeToggle.vue
+++ b/frontend/components/ThemeToggle.vue
@@ -1,5 +1,5 @@
<template>
- <button @click="toggleColorMode">
+ <button @click="toggleColorMode" style="background: none">
<svg v-if="colorMode.value === 'light'" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
diff --git a/frontend/composables/icons.ts b/frontend/composables/icons.ts
new file mode 100644
index 00000000..ebb5080d
--- /dev/null
+++ b/frontend/composables/icons.ts
@@ -0,0 +1,21 @@
+const icons = {
+ cdn: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M485-440h163q26 0 44-18t18-44q0-26-18-44.5T648-565h-2q-5-32-29-53.5T560-640q-26 0-47 13.5T481-590q-30 2-50.5 23.5T410-515q0 30 21.5 52.5T485-440ZM120-120q-33 0-56.5-23.5T40-200v-520h80v520h680v80H120Zm160-160q-33 0-56.5-23.5T200-360v-440q0-33 23.5-56.5T280-880h200l80 80h280q33 0 56.5 23.5T920-720v360q0 33-23.5 56.5T840-280H280Zm0-80h560v-360H527l-80-80H280v440Zm0 0v-440 440Z"/></svg>`,
+ categories: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M320-320h480v-480h-80v280l-100-60-100 60v-280H320v480Zm0 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm360-720h200-200Zm-200 0h480-480Z"/></svg>`,
+ backup: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M260-160q-91 0-155.5-63T40-377q0-78 47-139t123-78q17-72 85-137t145-65q33 0 56.5 23.5T520-716v242l64-62 56 56-160 160-160-160 56-56 64 62v-242q-76 14-118 73.5T280-520h-20q-58 0-99 41t-41 99q0 58 41 99t99 41h480q42 0 71-29t29-71q0-42-29-71t-71-29h-60v-80q0-48-22-89.5T600-680v-93q74 35 117 103.5T760-520q69 8 114.5 59.5T920-340q0 75-52.5 127.5T740-160H260Zm220-358Z"/></svg>`,
+ new_page: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-280h80v-160h160v-80H520v-160h-80v160H280v80h160v160ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>`,
+ settings: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M400-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM80-160v-112q0-33 17-62t47-44q51-26 115-44t141-18h14q6 0 12 2-8 18-13.5 37.5T404-360h-4q-71 0-127.5 18T180-306q-9 5-14.5 14t-5.5 20v32h252q6 21 16 41.5t22 38.5H80Zm560 40-12-60q-12-5-22.5-10.5T584-204l-58 18-40-68 46-40q-2-14-2-26t2-26l-46-40 40-68 58 18q11-8 21.5-13.5T628-460l12-60h80l12 60q12 5 22.5 11t21.5 15l58-20 40 70-46 40q2 12 2 25t-2 25l46 40-40 68-58-18q-11 8-21.5 13.5T732-180l-12 60h-80Zm40-120q33 0 56.5-23.5T760-320q0-33-23.5-56.5T680-400q-33 0-56.5 23.5T600-320q0 33 23.5 56.5T680-240ZM400-560q33 0 56.5-23.5T480-640q0-33-23.5-56.5T400-720q-33 0-56.5 23.5T320-640q0 33 23.5 56.5T400-560Zm0-80Zm12 400Z"/></svg>`,
+ security: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m438-338 226-226-57-57-169 169-84-84-57 57 141 141Zm42 258q-139-35-229.5-159.5T160-516v-244l320-120 320 120v244q0 152-90.5 276.5T480-80Zm0-84q104-33 172-132t68-220v-189l-240-90-240 90v189q0 121 68 220t172 132Zm0-316Z"/></svg>`,
+ close: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg>`,
+ profil: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>`,
+
+ draft: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--turquoise)" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>`,
+ folder: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--yellow);" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>`,
+ file: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--red);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>`,
+ file_parent: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--green);" d="M320-320h200v-200H320v200Zm0-280h480v-200H320v200Zm280 280h200v-200H600v200Zm-280 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Z"/></svg>`,
+ archive: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none"><rect x="2.5" y="2.5" width="11" height="11" rx="1.5" fill="var(--grey-bg)" stroke="var(--grey)"/><rect x="6" y="4" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="6" y="8" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="8" y="10" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="8" y="6" width="2" height="2" rx="0.5" fill="var(--grey)"/></svg>`,
+};
+export type IconName = keyof typeof icons;
+
+export function useIcon(name: IconName) {
+ return icons[name];
+}
diff --git a/frontend/composables/utils.ts b/frontend/composables/utils.ts
index 0557010b..b00d3b4d 100644
--- a/frontend/composables/utils.ts
+++ b/frontend/composables/utils.ts
@@ -1,3 +1,5 @@
+const CDN = `${import.meta.env.VITE_BASE_API}/static`;
+
const colors = ['var(--blue)', 'var(--turquoise)', 'var(--yellow)', 'var(--red)', 'var(--red)'];
export function useColorHash(str: string): string {
@@ -23,9 +25,9 @@ export interface FetchOptions {
export const isMobile = () => (import.meta.client ? window.innerWidth <= 768 : false);
export const baseUrl = import.meta.env.VITE_BASE_API?.toString() || '';
-import type { DB_Document, DB_Category, DB_Ressource, User } from '../stores/db_strustures';
-
-export async function makeRequest(route: string, method: string, body: Object, retry = false): Promise<APIResult<DB_Document | DB_Category | DB_Ressource | DB_Document[] | DB_Category[] | DB_Ressource[] | User>> {
+import type { User } from '../stores/db_strustures';
+export async function makeRequest<T>(route: string, method: string, body: Object, retry = false): Promise<APIResult<T>> {
+ const userStore = useUserStore();
console.log(`[API] Requesting ${method} ${route}`);
const response = await fetch(`${baseUrl}/api/v1/${route}`, {
method: method,
@@ -36,7 +38,7 @@ export async function makeRequest(route: string, method: string, body: Object, r
if (response.status === 401 && !retry) {
console.log('\x1b[41m[AUTH]\x1b[0m Access token invalid. Getting new access token...');
- const login = await makeRequest(`auth/refreshToken/152981937240150016`, 'GET', {}, true); // TODO: remove hardcoded user_id
+ const login = await makeRequest(`auth/refreshToken/${userStore.user?.id}`, 'GET', {}, true);
if (login.status === 'success') {
console.log('\x1b[42m[AUTH]\x1b[0m New access token received.');
return await makeRequest(route, method, body, true);
@@ -60,28 +62,52 @@ export function logOut() {
if (!import.meta.client) return;
localStorage.removeItem('isLoggedIn');
}
+export function useAvatar(user: User): string {
+ return user.avatar ? CDN + user.avatar : CDN + '/webp/default.svg';
+}
+export function parseUserAgent(uaString?: string) {
+ if (!uaString) return { os: 'Unknown OS', browser: 'Unknown Browser' };
+ const osList = [
+ { name: 'Windows 10', regex: /Windows NT 10.0/ },
+ { name: 'Windows 8.1', regex: /Windows NT 6.3/ },
+ { name: 'Windows 8', regex: /Windows NT 6.2/ },
+ { name: 'Windows 7', regex: /Windows NT 6.1/ },
+ { name: 'Windows Vista', regex: /Windows NT 6.0/ },
+ { name: 'Windows XP', regex: /Windows NT 5.1/ },
+ { name: 'Mac OS X', regex: /Mac OS X ([\d_]+)/ },
+ { name: 'iOS', regex: /iPhone|iPad/ },
+ { name: 'Android', regex: /Android/ },
+ { name: 'Linux', regex: /Linux/ },
+ ];
-export const useBreadcrumbs = () => {
- const route = useRoute();
+ const browserList = [
+ { name: 'Chrome', regex: /Chrome\/([0-9.]+)/ },
+ { name: 'Firefox', regex: /Firefox\/([0-9.]+)/ },
+ { name: 'Safari', regex: /Safari\/([0-9.]+)/ },
+ { name: 'Edge', regex: /Edg\/([0-9.]+)/ },
+ { name: 'Opera', regex: /OPR\/([0-9.]+)/ },
+ { name: 'Internet Explorer', regex: /MSIE ([0-9.]+);/ },
+ ];
- const breadcrumbs: Ref<Array<{ name: string; path: string }>> = ref([]);
+ let os = 'Unknown OS';
+ for (let i = 0; i < osList.length; i++) {
+ if (osList[i]!.regex.test(uaString)) {
+ os = osList[i]!.name;
+ break;
+ }
+ }
- watch(
- () => ({
- path: route.path,
- name: route.meta.title,
- meta: route.meta,
- matched: route.matched,
- }),
- r => {
- console.log(r.name);
- },
- {
- immediate: true,
- },
- );
+ let browser = 'Unknown Browser';
+ for (let i = 0; i < browserList.length; i++) {
+ let match = uaString.match(browserList[i]!.regex);
+ if (match) {
+ browser = browserList[i]!.name + ' ' + match[1];
+ break;
+ }
+ }
return {
- breadcrumbs,
+ os: os,
+ browser: browser,
};
-};
+}
diff --git a/frontend/pages/dashboard.vue b/frontend/pages/dashboard.vue
index 7383ebeb..1c86f5ea 100644
--- a/frontend/pages/dashboard.vue
+++ b/frontend/pages/dashboard.vue
@@ -12,8 +12,7 @@ import Sidebar from '~/components/Sidebar/Sidebar.vue';
import { useDocumentsStore, useCategoriesStore } from '@/stores';
definePageMeta({ breadcrumb: 'Home' });
-useDocumentsStore().fetch();
-useCategoriesStore().fetch();
-
-useUserStore().fetch().then(r => console.log(r))
+await useDocumentsStore().fetch();
+await useCategoriesStore().fetch();
+await useUserStore().fetch()
</script>
\ No newline at end of file
diff --git a/frontend/pages/dashboard/categories/edit.vue b/frontend/pages/dashboard/categories/edit.vue
index 122e4a9b..d4cc23aa 100644
--- a/frontend/pages/dashboard/categories/edit.vue
+++ b/frontend/pages/dashboard/categories/edit.vue
@@ -30,8 +30,8 @@
<input type="number" v-model.number="category.order" id="order" />
</div>
<div style="display: flex;">
- <button type="submit" class="btn update">Update</button>
- <button class="btn delete" @click="deleteCategory()">Delete</button>
+ <button class="btn danger" @click="deleteCategory()">Delete</button>
+ <button type="submit" class="btn primary">Update</button>
</div>
</form>
</div>
@@ -84,30 +84,10 @@ h2 {
.input-group {
margin-bottom: 20px;
- position: relative;
}
-
-
-.btn {
- display: block;
- font-weight: 600;
- border: 2px solid var(--bg-contrast);
-
- &.update {
- background-color: $primary-400;
-
- &:hover {
- background-color: $primary-500;
- }
- }
-
- &.delete {
- background-color: $red;
-
- &:hover {
- background-color: darken($red, 10%);
- }
- }
+input,
+textarea {
+ width: 100%;
}
</style>
\ No newline at end of file
diff --git a/frontend/pages/dashboard/categories/new.vue b/frontend/pages/dashboard/categories/new.vue
index e4c65bf7..ec96f994 100644
--- a/frontend/pages/dashboard/categories/new.vue
+++ b/frontend/pages/dashboard/categories/new.vue
@@ -24,7 +24,7 @@
<label for="order">Ordre</label>
<input type="number" v-model.number="category.order" id="order" />
</div>
- <button type="submit" class="submit">Créer</button>
+ <button type="submit" class="btn primary">Create</button>
</form>
</div>
</div>
@@ -70,16 +70,4 @@ h2 {
margin-bottom: 20px;
position: relative;
}
-
-.submit {
- display: block;
- font-weight: 600;
- border: 2px solid var(--bg-contrast);
- background-color: $primary-400;
- color: var(--font-color);
-
- &:hover {
- background-color: $primary-500;
- }
-}
</style>
\ No newline at end of file
diff --git a/frontend/pages/dashboard/settings.vue b/frontend/pages/dashboard/settings.vue
new file mode 100644
index 00000000..d74e211b
--- /dev/null
+++ b/frontend/pages/dashboard/settings.vue
@@ -0,0 +1,342 @@
+<template>
+ <div :class="{ 'modal-mask': !isMobile() }">
+ <div class="component">
+ <nav>
+ <span>Account settings</span>
+ <div class="user" v-if="store.user">
+ <img :src="useAvatar(store.user)" alt="Avatar" style="width: 25px; height: 25px; border-radius: 50%" />
+ <div>
+ <div class="username">{{ store.user.username }}</div>
+ <div class="email">{{ store.user.email }}</div>
+ </div>
+ </div>
+ <NuxtLink to="?p=profile"><Icon fill="var(--font-color)" name="profil" />My profile</NuxtLink>
+ <NuxtLink to="?p=preferences"><Icon fill="var(--font-color)" name="settings" />Preferences</NuxtLink>
+ <NuxtLink to="?p=security"><Icon fill="var(--font-color)" name="security" />Security</NuxtLink>
+ <NuxtLink to="?p=backup"><Icon fill="var(--font-color)" name="backup" />Backup</NuxtLink>
+ <span>Workspaces</span>
+ <NuxtLink to="/dashboard/categories"><Icon fill="var(--font-color)" name="categories" />Manage categories</NuxtLink>
+ <NuxtLink to="/dashboard/docs"><Icon fill="var(--font-color)" name="draft" />Manage documents</NuxtLink>
+ </nav>
+ <div class="content">
+ <button @click="close" class="close-btn"><Icon name="close" :big="true" /></button>
+ <div v-show="currentPage === 'profile'" class="page profil_page">
+ <h1>My Profile</h1>
+ <form v-if="store.user" @submit.prevent="updateUser">
+ <div class="form-group">
+ <label for="username">Username</label>
+ <input id="username" v-model="store.user.username" type="text" disabled required />
+ </div>
+ <div class="form-group">
+ <label for="firstname">First Name</label>
+ <input id="firstname" v-model="store.user.firstname" type="text" />
+ </div>
+ <div class="form-group">
+ <label for="lastname">Last Name</label>
+ <input id="lastname" v-model="store.user.lastname" type="text" />
+ </div>
+ <div class="form-group">
+ <label for="email">Email</label>
+ <input id="email" v-model="store.user.email" type="email" required />
+ </div>
+ <div class="form-group avatar-group">
+ <label>Avatar</label>
+ <img :src="avatarPreview || useAvatar(store.user)" class="avatar" @click="selectAvatar" />
+ <input ref="avatarInput" type="file" accept="image/*" @change="previewAvatar" style="display: none" />
+ </div>
+ <button type="submit" class="btn primary">Update</button>
+ </form>
+ </div>
+ <div v-show="currentPage === 'preferences'" class="page preferences">
+ <h1>Preferences</h1>
+ <p>Preferences content goes here...</p>
+ </div>
+ <div v-show="currentPage === 'security'" class="page security_page">
+ <h1>Security</h1>
+ <h2>Last connection</h2>
+ <div class="last_connection" v-if="store.last_connection">
+ <div style="display: flex">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="569.4 86.3 83.6 48.2" width="100px">
+ <path fill="var(--cl-chassis-back, black)" d="M577 89.8c0-1.4.2-2 .6-2.6.5-.5 1.2-.9 2.8-.9h61.7c1.4 0 2 .3 2.5.8s.7 1.2.7 2.7v41c0 1.4-.2 2-.5 2.4a2.7 2.7 0 0 1-2.2 1.1h-63c-.8 0-1.6-.3-2-1-.4-.4-.6-1-.6-2.5v-41Z"></path>
+ <path fill="var(--cl-chassis-screen, #323232)" d="M578.4 132.9h65.5c.3 0 .6-.2.8-.4.2-.2.2-.5.2-1.4V89.8c0-1.2-.1-2-.6-2.4-.5-.5-1-.7-2.2-.7h-61.7c-1.3 0-2 .3-2.5.8-.4.4-.5 1-.5 2.3v41.3c0 .9 0 1.2.2 1.4.2.2.5.4.8.4Z"></path>
+ <path fill-rule="evenodd" stroke="var(--cl-chassis-back1, 'gold')" stroke-width="0.3" d="M611.2 88.5a.3.3 0 1 0 0-.5.3.3 0 1 0 0 .5Z" clip-rule="evenodd"></path>
+ <path fill="var(--cl-chassis-bottom, #191919)" fill-rule="evenodd" d="M569.4 133.3v-.5H653v.5s-1.9.6-4 .8c-1.4.1-3.7.4-8.9.4h-57.4c-4.5 0-8.3-.3-10-.5-1.7-.2-3.3-.7-3.3-.7Z" clip-rule="evenodd"></path>
+ <path fill="var(--cl-screen, #111111)" fill-rule="evenodd" d="M579.7 89.5h63v39.4h-63V89.5Z" clip-rule="evenodd"></path>
+ </svg>
+ <div>
+ <p><strong>Last connection:</strong> {{ new Date(store.last_connection.timestamp).toLocaleString() }}</p>
+ <p><strong>IP:</strong> {{ store.last_connection.ip_adress }} ({{ store.last_connection.location }})</p>
+ <p><strong>Browser:</strong> {{ parseUserAgent(store.last_connection.user_agent).browser }}</p>
+ <p><strong>OS:</strong> {{ parseUserAgent(store.last_connection.user_agent).os }}</p>
+ </div>
+ </div>
+ <p>{{ store.last_connection.user_agent }}</p>
+ </div>
+ <p class="warning">If you don't recognize this connection, please change your password and click on "Log out from all devices".</p>
+ <h2>Password</h2>
+ <form @submit.prevent="changePassword">
+ <div class="form-group">
+ <label for="password">New password</label>
+ <input id="password" type="password" required v-model="passwordValue" />
+ </div>
+ <div class="form-group">
+ <label for="password_confirm">Confirm password</label>
+ <input id="password_confirm" type="password" required v-model="passwordConfirmValue" />
+ </div>
+ <button type="submit" class="btn primary">Update</button>
+ </form>
+ </div>
+ <div v-show="currentPage == 'backup'" class="page backup_page">
+ <h2>Create a Database Backup</h2>
+ <p>Click the button below to create a backup of your database.</p>
+ <button @click="submitFile">Create Backup</button>
+ <div v-if="isLoading" class="loading-spinner"></div>
+ <div class="link-section" v-if="downloadLink">
+ <p>Your backup is ready. You can copy the link to share it or download it.</p>
+ <input type="text" v-model="downloadLink" readonly placeholder="Backup Link" />
+ <button @click="copyLink">Copy Link</button>
+ <a :href="downloadLink" download="true" class="download">Download Backup</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, watchEffect } from 'vue';
+import { useRoute } from 'vue-router';
+import { useUserStore, useRessourcesStore, useNotifications } from '@/stores';
+
+const route = useRoute();
+const currentPage = ref(route.query.p || 'profile');
+const store = useUserStore();
+const ressourcesStore = useRessourcesStore();
+const avatarInput = ref<HTMLInputElement | null>(null);
+const passwordValue = ref('');
+const passwordConfirmValue = ref('');
+
+watchEffect(() => (currentPage.value = route.query.p || 'profile'));
+
+const close = () => useRouter().push('/dashboard');
+const avatarPreview = ref('');
+const selectAvatar = () => avatarInput.value?.click();
+
+const uploadAvatar = async () => {
+ if (!store.user) return;
+ const file = avatarInput.value?.files?.[0];
+ if (!file) return;
+ const body = new FormData();
+ body.append('file', file);
+ const r = await ressourcesStore.postAvatar(body);
+ return r.transformed_path || r.original_path;
+};
+const previewAvatar = (event: Event) => {
+ if (!store.user) return;
+ const target = event.target as HTMLInputElement;
+ const file = target.files?.[0];
+ if (!file) return;
+ const reader = new FileReader();
+ reader.onload = () => (avatarPreview.value = reader.result as string);
+ reader.readAsDataURL(file);
+};
+
+const updateUser = async () => {
+ if (!store.user) return;
+ const newAvatar = await uploadAvatar();
+ if (newAvatar) store.user.avatar = newAvatar;
+ store
+ .update(store.user)
+ .then(() => useNotifications().add({ title: 'Success:', message: 'User updated', type: 'success', timeout: 5000 }))
+ .catch(e => useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 5000 }));
+};
+const changePassword = async () => {
+ if (!store.user) return;
+ if (passwordValue.value !== passwordConfirmValue.value) return;
+ store.updatePassword(passwordValue.value);
+};
+
+const downloadLink = ref<string | null>(null);
+const copyLink = () => navigator.clipboard.writeText(downloadLink.value!);
+const isLoading = ref(false);
+
+async function submitFile() {
+ isLoading.value = true;
+ const response = await fetch(`${import.meta.env.VITE_BASE_API}/api/v1/backups`, {
+ method: 'POST',
+ credentials: 'include',
+ });
+ const result = await response.json();
+ isLoading.value = false;
+ if (result.status != 'success') {
+ useNotifications().add({ type: 'error', title: 'Error', message: result.message, timeout: 5000 });
+ return;
+ }
+ downloadLink.value = `${import.meta.env.VITE_BASE_API}/static${result.result.url}`;
+}
+</script>
+
+<style scoped lang="scss">
+.component {
+ display: flex;
+ border-radius: 8px;
+ height: 90%;
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
+ background-color: var(--bg-color);
+ width: 1150px;
+ height: calc(-100px + 100vh);
+ max-width: calc(-100px + 100vw);
+ max-height: 715px;
+ margin: auto;
+
+ nav {
+ gap: 1rem;
+ background-color: var(--bg-contrast);
+ padding: 1rem;
+ border-top-left-radius: 8px;
+ border-bottom-left-radius: 8px;
+
+ span {
+ font-size: 0.9rem;
+ font-weight: 500;
+ color: var(--font-color-light);
+ }
+
+ a {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ margin: 0.5rem;
+ text-decoration: none;
+ color: inherit;
+ border-radius: 4px;
+
+ &:hover {
+ background-color: var(--bg-contrast-2);
+ }
+ }
+
+ .user {
+ display: flex;
+ align-items: center;
+
+ div {
+ font-size: 0.8rem;
+ margin-left: 5px;
+
+ .email {
+ font-size: 0.7rem;
+ color: var(--font-color-light);
+ }
+ }
+ }
+ }
+}
+.content {
+ position: relative;
+ flex: 1;
+ padding: 2rem;
+}
+.close-btn {
+ position: absolute;
+ right: 0px;
+ top: 1rem;
+ background: none;
+}
+form {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+
+ .form-group {
+ display: flex;
+ flex-direction: column;
+ }
+}
+.profil_page {
+ .avatar-group {
+ display: flex;
+ gap: 1rem;
+ }
+ .avatar {
+ width: 100px;
+ height: 100px;
+ border-radius: 50%;
+ object-fit: cover;
+ cursor: pointer;
+ border: 1px solid var(--border-color);
+ }
+}
+
+.security_page {
+ .last_connection {
+ align-items: center;
+ padding: 0.3rem 0.5rem;
+ border-radius: 15px;
+ background-color: var(--bg-contrast-2);
+ }
+ p {
+ margin: 0.5rem;
+ font-size: 0.9rem;
+ }
+
+ .warning {
+ color: var(--red);
+ font-size: 0.9rem;
+ }
+}
+.backup_page {
+ .backup-component {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 2rem;
+ margin: 0 auto;
+ height: min-content;
+
+ h2 {
+ margin-bottom: 1rem;
+ }
+
+ input {
+ margin-bottom: 1rem;
+ }
+
+ .download {
+ margin-left: 15px;
+ }
+ }
+
+ .loading-spinner {
+ border: 5px solid #f3f3f3;
+ border-top: 5px solid $primary-400;
+ border-radius: 50%;
+ width: 50px;
+ height: 50px;
+ animation: spin 1s linear infinite;
+ }
+
+ @keyframes spin {
+ 0% {
+ transform: rotate(0deg);
+ }
+
+ 100% {
+ transform: rotate(360deg);
+ }
+ }
+}
+
+@media screen and (max-width: 920px) {
+ .component {
+ width: 100%;
+ max-width: 100%;
+ height: 100%;
+ display: block;
+ box-shadow: none;
+ }
+ .close-btn {
+ display: none;
+ }
+}
+</style>
diff --git a/frontend/stores/db_strustures.d.ts b/frontend/stores/db_strustures.d.ts
index afe53713..f9d83179 100644
--- a/frontend/stores/db_strustures.d.ts
+++ b/frontend/stores/db_strustures.d.ts
@@ -36,6 +36,16 @@ export interface User {
email: string;
created_timestamp: string;
}
+
+export interface ConnectionLog {
+ id: string;
+ user_id: string;
+ ip_adress?: string;
+ user_agent?: string;
+ location?: string;
+ type: string;
+ timestamp: string; // BIGINT converted to string
+}
export interface DB_Ressource {
id: string;
filename: string;
diff --git a/frontend/stores/documents.store.ts b/frontend/stores/documents.store.ts
index 6f63c4e3..2dc1f90b 100644
--- a/frontend/stores/documents.store.ts
+++ b/frontend/stores/documents.store.ts
@@ -43,7 +43,7 @@ export const useDocumentsStore = defineStore('documents', {
fetch: function <T extends FetchOptions>(opts?: T): Promise<'id' extends keyof T ? Document : Document[]> {
console.log(`[store/documents] Fetching documents with options: ${JSON.stringify(opts)}`);
return new Promise(async (resolve, reject) => {
- const request = await makeRequest(`documents/${opts?.id || ''}?all=true`, 'GET', {});
+ const request = await makeRequest(`documents/${opts?.id || ''}`, 'GET', {});
if (request.status == 'success') {
if (opts?.id) {
const index = this.documents.findIndex(d => d.id == opts?.id);
diff --git a/frontend/stores/index.ts b/frontend/stores/index.ts
index d3645028..6d2c0d89 100644
--- a/frontend/stores/index.ts
+++ b/frontend/stores/index.ts
@@ -2,4 +2,5 @@ export * from './documents.store';
export * from './categories.store';
export * from './notifications.store';
export * from './ressources.store';
+export * from './user.store';
export type * from './db_strustures';
diff --git a/frontend/stores/ressources.store.ts b/frontend/stores/ressources.store.ts
index 915a05da..865cdbd3 100644
--- a/frontend/stores/ressources.store.ts
+++ b/frontend/stores/ressources.store.ts
@@ -27,6 +27,14 @@ export const useRessourcesStore = defineStore('ressources', {
} else reject(request.message);
});
},
+ postAvatar(ressource: FormData): Promise<{ original_path: string; transformed_path: string }> {
+ return new Promise(async (resolve, reject) => {
+ const request = await makeRequest(`ressources/avatar`, 'POST', ressource);
+ if (request.status == 'success') {
+ resolve(request.result as { original_path: string; transformed_path: string });
+ } else reject(request.message);
+ });
+ },
delete(id: string) {
return new Promise(async (resolve, reject) => {
const request = await makeRequest(`ressources/${id}`, 'DELETE', {});
diff --git a/frontend/stores/user.store.ts b/frontend/stores/user.store.ts
index 0e6c5861..07ab9ca0 100644
--- a/frontend/stores/user.store.ts
+++ b/frontend/stores/user.store.ts
@@ -1,14 +1,36 @@
import { defineStore } from 'pinia';
-import type { User } from './db_strustures'; // Assurez-vous d'avoir les bonnes définitions de types
+import type { User, ConnectionLog } from './db_strustures'; // Assurez-vous d'avoir les bonnes définitions de types
export const useUserStore = defineStore('user', {
state: () => ({
- user: ref<User | null>(null),
+ user: ref<User>(),
+ last_connection: null as ConnectionLog | null,
}),
actions: {
fetch() {
return new Promise(async (resolve, reject) => {
- const request = await makeRequest(`users/@me`, 'GET', {});
+ const responce = await makeRequest<{ user: User; last_connection: ConnectionLog }>(`users/@me`, 'GET', {});
+ if (responce.status === 'success') {
+ if (responce.result?.user) this.user = responce.result.user as User;
+ if (responce.result?.last_connection) this.last_connection = responce.result.last_connection as ConnectionLog;
+ return resolve(this.user);
+ } else reject(responce.message);
+ });
+ },
+ update(user: User) {
+ return new Promise(async (resolve, reject) => {
+ if (!this.user) return;
+ const request = await makeRequest(`users/${user.id}`, 'PATCH', user);
+ if (request.status === 'success') {
+ this.user = request.result as User;
+ return resolve(this.user);
+ } else reject(request.message);
+ });
+ },
+ updatePassword(newPassword: string) {
+ return new Promise(async (resolve, reject) => {
+ if (!this.user) return;
+ const request = await makeRequest(`users/${this.user.id}/password`, 'PATCH', { password: newPassword });
if (request.status === 'success') {
this.user = request.result as User;
return resolve(this.user);
diff --git a/frontend/styles/_variables.scss b/frontend/styles/_variables.scss
index 9d0cc4fe..b41ef3e7 100644
--- a/frontend/styles/_variables.scss
+++ b/frontend/styles/_variables.scss
@@ -10,7 +10,7 @@ $green: #009879;
$grey: #ffffffd9;
$black: #27323A;
-$primary-400: #007aff;
+$primary-400: #334155;
$primary-300: lighten($primary-400, 10%);
$primary-500: darken($primary-400, 10%);
@@ -24,6 +24,8 @@ $transition-duration: 0.3s;
:root {
+ --primary-400: #334155;
+
--bg-color: #fff;
--bg-contrast: #F1F6FD;
--bg-contrast-2: #ECF2FF;
diff --git a/frontend/styles/main.scss b/frontend/styles/main.scss
index 1ec73290..c3c65e47 100644
--- a/frontend/styles/main.scss
+++ b/frontend/styles/main.scss
@@ -46,6 +46,29 @@
display: flex;
}
+.btn {
+ display: block;
+ font-weight: 600;
+ margin-right: 5px;
+ color: #fff;
+
+ &.primary {
+ background: var(--primary-400);
+
+ &:hover {
+ background: $primary-500;
+ }
+ }
+
+ &.danger {
+ background: $red;
+
+ &:hover {
+ background: darken($red, 10%);
+ }
+ }
+}
+
body {
background: var(--bg-color);
color: var(--font-color);
diff --git a/frontend/styles/theme.scss b/frontend/styles/theme.scss
index 36a32c91..5ae4670c 100644
--- a/frontend/styles/theme.scss
+++ b/frontend/styles/theme.scss
@@ -121,16 +121,22 @@ textarea {
color: var(--font-color);
border-radius: 6px;
transition: border-color $transition-duration, box-shadow $transition-duration;
+ font-size: 1rem;
&:focus {
box-shadow: 0 0 5px rgba(var(--primary-color-rgb), 0.2);
}
+
+ &:disabled {
+ opacity: 0.8;
+ cursor: not-allowed;
+ }
}
label {
display: block;
margin-bottom: 0.5rem;
- font-weight: 600;
+ font-weight: 500;
}
mark {
@@ -154,6 +160,7 @@ p {
select {
font-family: $external-font;
+ font-size: 15px;
border: 1px solid var(--border-color);
border-radius: 5px;
}
diff --git a/old.txt b/old.txt
new file mode 100644
index 00000000..9bdd2e6e
--- /dev/null
+++ b/old.txt
@@ -0,0 +1,21 @@
+const mysqldump = spawn('mysqldump', [
+ '-u',
+ `${process.env.DATABASE_USER}`,
+ `-p${process.env.DATABASE_PASSWORD}`,
+ 'alexandrie',
+ ]);
+
+ const wstream = createWriteStream(`${this.app.config.upload_path}/backups/${name}.sql`);
+ const backupPromise = new Promise<void | string>((resolve, reject) => {
+ mysqldump.stdout
+ .pipe(wstream)
+ .on('finish', function () {
+ resolve();
+ })
+ .on('error', function (err) {
+ reject(err.message);
+ });
+ });
+ backupPromise
+ .then(() => res.json(success({ url: `/backups/${name}.sql` })))
+ .catch((err: Error) => res.json(error(err.message)));
\ No newline at end of file