π 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
Add backup system
Veauville Raphael514baf7c5caa
diff --git a/.gitignore b/.gitignoreindex 7b87e07d..a32fa2c6 100644--- a/.gitignore+++ b/.gitignore@@ -1,5 +1,7 @@#Public diruploads/images/*uploads/webp/*+uploads/backups/*!uploads/images/default!uploads/webp/default+!uploads/backups/defaultdiff --git a/backend/app.ts b/backend/app.tsindex cdefd895..b99bc513 100644--- a/backend/app.ts+++ b/backend/app.ts@@ -16,12 +16,14 @@ export class App {public port: string;public snowflake: Snowflake;public db: Pool;+ public uploads_dir: string;constructor() {Logger.debug(`Starting in ${process.env.NODE_ENV} mode...`);this.app = express();this.port = process.env.PORT || '3000';this.snowflake = new Snowflake(1661327668261);this.db = db('localhost', process.env.DATABASE_USER, process.env.DATABASE_PASSWORD, 'alexandrie');+ this.uploads_dir = join(__dirname, '../../uploads');}private async handleRoutes() {const directories = readdirSync(join(__dirname, 'routes'));diff --git a/backend/controllers/backups.controller.ts b/backend/controllers/backups.controller.tsnew file mode 100644index 00000000..ab3310ee--- /dev/null+++ b/backend/controllers/backups.controller.ts@@ -0,0 +1,43 @@+import { createWriteStream, unlinkSync, readdirSync } from 'fs';+import { spawn } from 'child_process';++import type { Request, Response } from 'express';+import type { App } from '../app';+import { error, success } from '../utils/functions';++export default class CategoriesController {+ app: App;+ constructor(app: App) {+ this.app = app;+ }++ async add(_: Request, res: Response) {+ // Clean the uploads directory+ const files = readdirSync(this.app.uploads_dir + '/backups');+ for (const file of files) {+ if (file.endsWith('.sql')) unlinkSync(`${this.app.uploads_dir}/backups/${file}`);+ }+ const name = new Date().toISOString().split('T')[0] + '-' + Date.now();+ const mysqldump = spawn('mysqldump', [+ '-u',+ `${process.env.DATABASE_USER}`,+ `-p${process.env.DATABASE_PASSWORD}`,+ 'alexandrie',+ ]);++ const wstream = createWriteStream(`${this.app.uploads_dir}/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)));+ }+}diff --git a/backend/dist/app.js b/backend/dist/app.jsindex f4ce5bb3..5b2aab47 100644--- a/backend/dist/app.js+++ b/backend/dist/app.js@@ -35,11 +35,18 @@ class App {writable: true,value: void 0});+ Object.defineProperty(this, "uploads_dir", {+ enumerable: true,+ configurable: true,+ writable: true,+ value: void 0+ });Logger_1.default.debug(`Starting in ${process.env.NODE_ENV} mode...`);this.app = (0, express_1.default)();this.port = process.env.PORT || '3000';this.snowflake = new Snowflake_1.Snowflake(1661327668261);this.db = (0, db_1.default)('localhost', process.env.DATABASE_USER, process.env.DATABASE_PASSWORD, 'alexandrie');+ this.uploads_dir = (0, path_1.join)(__dirname, '../../uploads');}async handleRoutes() {const directories = (0, fs_1.readdirSync)((0, path_1.join)(__dirname, 'routes'));diff --git a/backend/dist/app.js.map b/backend/dist/app.js.mapindex 120d42ef..4d1cae51 100644--- a/backend/dist/app.js.map+++ b/backend/dist/app.js.map@@ -1 +1 @@-{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;AAAA,2BAAiC;AACjC,+BAA4B;AAC5B,8DAA8B;AAM9B,6DAA6B;AAC7B,oEAAoC;AACpC,iDAAmD;AACnD,iDAA8C;AAE9C,MAAa,GAAG;IAKd;QAJQ;;;;;WAAI;QACL;;;;;WAAa;QACb;;;;;WAAqB;QACrB;;;;;WAAS;QAEd,gBAAM,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,GAAG,CAAC,QAAQ,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC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,EAAE,CAAC;QAC1B,MAAM,aAAa,GAAG;YACpB,QAAQ,EAAE,QAAQ;YAClB,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,UAAU,GAAa;gBACjC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChD,CAAC;SACF,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAO,CAAC,MAAM,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,eAAe,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;QAEzF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;YAC9B,gBAAM,CAAC,OAAO,CAAC,mBAAmB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAU,EAAE,GAAa,EAAE,EAAE;YAC9C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,0BAAc,EAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnED,kBAmEC","sourcesContent":["import { readdirSync } from 'fs';\nimport { join } from 'path';\nimport express from 'express';\nimport { Pool } from 'mysql2';\nimport type { Request, Response } from 'express';\n\nimport type { Iroute } from './types';\n\nimport db from './models/db';\nimport Logger from './utils/Logger';\nimport { checkAndChange } from './utils/functions';\nimport { Snowflake } from './utils/Snowflake';\n\nexport class App {\n private app;\n public port: string;\n public snowflake: Snowflake;\n public db: Pool;\n constructor() {\n Logger.debug(`Starting in ${process.env.NODE_ENV} mode...`);\n this.app = express();\n this.port = process.env.PORT || '3000';\n this.snowflake = new Snowflake(1661327668261);\n this.db = db('localhost', process.env.DATABASE_USER, process.env.DATABASE_PASSWORD, 'alexandrie');\n }\n private async handleRoutes() {\n const directories = readdirSync(join(__dirname, 'routes'));\n for (const dir of directories) {\n const routes = readdirSync(join(__dirname, `routes/${dir}`)).filter(file => file.endsWith('.js'));\n for (const file of routes) {\n const getFile = (await import(join(__dirname, `routes/${dir}/${file}`))).default;\n const fileInfos = getFile(this) as Iroute;\n this.app.use(`/api/v${fileInfos.version}/${fileInfos.route}`, fileInfos.router());\n Logger.info(`Loaded route:`, `/api/v${fileInfos.version}/${fileInfos.route}`);\n }\n }\n }\n private handleMiddlewares(): void {\n this.app.use(express.urlencoded({ extended: true, limit: '5mb' }));\n this.app.use(express.json({ limit: '5mb' }));\n this.app.use(function (req: Request, res: Response, next: Function) {\n const origin = req.headers.origin;\n if (!origin || ![process.env.DOMAIN_CLIENT, process.env.DOMAIN_DASHBOARD].includes(origin)) return next();\n res.setHeader('Access-Control-Allow-Origin', origin);\n res.setHeader(\n 'Access-Control-Allow-Headers',\n 'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers',\n );\n res.setHeader('Access-Control-Allow-Credentials', 'true');\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n next();\n });\n if (process.env.NODE_ENV !== 'production') {\n Logger.warn('Morgan is enabled in development mode.');\n const morgan = require('morgan')('dev');\n this.app.use(morgan);\n }\n }\n public async start() {\n this.handleMiddlewares();\n await this.handleRoutes();\n const staticOptions = {\n dotfiles: 'ignore',\n etag: false,\n index: false,\n maxAge: '7d',\n redirect: false,\n setHeaders: function (res: Response) {\n res.set('x-timestamp', Date.now().toString());\n },\n };\n this.app.use('/static', express.static(join(__dirname, '../../uploads'), staticOptions));\n\n this.app.listen(this.port, () => {\n Logger.success(`Started on port ${this.port}`);\n });\n this.app.all('*', (_: Request, res: Response) => {\n res.status(404).json(checkAndChange(new Error('404 not found')));\n });\n }\n}\n"]}\ No newline at end of file+{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;AAAA,2BAAiC;AACjC,+BAA4B;AAC5B,8DAA8B;AAM9B,6DAA6B;AAC7B,oEAAoC;AACpC,iDAAmD;AACnD,iDAA8C;AAE9C,MAAa,GAAG;IAMd;QALQ;;;;;WAAI;QACL;;;;;WAAa;QACb;;;;;WAAqB;QACrB;;;;;WAAS;QACT;;;;;WAAoB;QAEzB,gBAAM,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,GAAG,CAAC,QAAQ,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAA,YAAE,EAAC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QAClG,IAAI,CAAC,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACtD,CAAC;IACO,KAAK,CAAC,YAAY;QACxB,MAAM,WAAW,GAAG,IAAA,gBAAW,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC3D,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE;YAC7B,MAAM,MAAM,GAAG,IAAA,gBAAW,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC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AE,GAAa,EAAE,EAAE;YAC9C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,0BAAc,EAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArED,kBAqEC","sourcesContent":["import { readdirSync } from 'fs';\nimport { join } from 'path';\nimport express from 'express';\nimport { Pool } from 'mysql2';\nimport type { Request, Response } from 'express';\n\nimport type { Iroute } from './types';\n\nimport db from './models/db';\nimport Logger from './utils/Logger';\nimport { checkAndChange } from './utils/functions';\nimport { Snowflake } from './utils/Snowflake';\n\nexport class App {\n private app;\n public port: string;\n public snowflake: Snowflake;\n public db: Pool;\n public uploads_dir: string;\n constructor() {\n Logger.debug(`Starting in ${process.env.NODE_ENV} mode...`);\n this.app = express();\n this.port = process.env.PORT || '3000';\n this.snowflake = new Snowflake(1661327668261);\n this.db = db('localhost', process.env.DATABASE_USER, process.env.DATABASE_PASSWORD, 'alexandrie');\n this.uploads_dir = join(__dirname, '../../uploads');\n }\n private async handleRoutes() {\n const directories = readdirSync(join(__dirname, 'routes'));\n for (const dir of directories) {\n const routes = readdirSync(join(__dirname, `routes/${dir}`)).filter(file => file.endsWith('.js'));\n for (const file of routes) {\n const getFile = (await import(join(__dirname, `routes/${dir}/${file}`))).default;\n const fileInfos = getFile(this) as Iroute;\n this.app.use(`/api/v${fileInfos.version}/${fileInfos.route}`, fileInfos.router());\n Logger.info(`Loaded route:`, `/api/v${fileInfos.version}/${fileInfos.route}`);\n }\n }\n }\n private handleMiddlewares(): void {\n this.app.use(express.urlencoded({ extended: true, limit: '5mb' }));\n this.app.use(express.json({ limit: '5mb' }));\n this.app.use(function (req: Request, res: Response, next: Function) {\n const origin = req.headers.origin;\n if (!origin || ![process.env.DOMAIN_CLIENT, process.env.DOMAIN_DASHBOARD].includes(origin)) return next();\n res.setHeader('Access-Control-Allow-Origin', origin);\n res.setHeader(\n 'Access-Control-Allow-Headers',\n 'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers',\n );\n res.setHeader('Access-Control-Allow-Credentials', 'true');\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n next();\n });\n if (process.env.NODE_ENV !== 'production') {\n Logger.warn('Morgan is enabled in development mode.');\n const morgan = require('morgan')('dev');\n this.app.use(morgan);\n }\n }\n public async start() {\n this.handleMiddlewares();\n await this.handleRoutes();\n const staticOptions = {\n dotfiles: 'ignore',\n etag: false,\n index: false,\n maxAge: '7d',\n redirect: false,\n setHeaders: function (res: Response) {\n res.set('x-timestamp', Date.now().toString());\n },\n };\n this.app.use('/static', express.static(join(__dirname, '../../uploads'), staticOptions));\n\n this.app.listen(this.port, () => {\n Logger.success(`Started on port ${this.port}`);\n });\n this.app.all('*', (_: Request, res: Response) => {\n res.status(404).json(checkAndChange(new Error('404 not found')));\n });\n }\n}\n"]}\ No newline at end of filediff --git a/backend/dist/controllers/backups.controller.js b/backend/dist/controllers/backups.controller.jsnew file mode 100644index 00000000..443abd2e--- /dev/null+++ b/backend/dist/controllers/backups.controller.js@@ -0,0 +1,47 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+const fs_1 = require("fs");+const child_process_1 = require("child_process");+const functions_1 = require("../utils/functions");+class CategoriesController {+ constructor(app) {+ Object.defineProperty(this, "app", {+ enumerable: true,+ configurable: true,+ writable: true,+ value: void 0+ });+ this.app = app;+ }+ async add(_, res) {+ // Clean the uploads directory+ const files = (0, fs_1.readdirSync)(this.app.uploads_dir + '/backups');+ for (const file of files) {+ if (file.endsWith('.sql'))+ (0, fs_1.unlinkSync)(`${this.app.uploads_dir}/backups/${file}`);+ }+ const name = new Date().toISOString().split('T')[0] + '-' + Date.now();+ const mysqldump = (0, child_process_1.spawn)('mysqldump', [+ '-u',+ `${process.env.DATABASE_USER}`,+ `-p${process.env.DATABASE_PASSWORD}`,+ 'alexandrie',+ ]);+ const wstream = (0, fs_1.createWriteStream)(`${this.app.uploads_dir}/backups/${name}.sql`);+ const backupPromise = new Promise((resolve, reject) => {+ mysqldump.stdout+ .pipe(wstream)+ .on('finish', function () {+ resolve();+ })+ .on('error', function (err) {+ reject(err.message);+ });+ });+ backupPromise+ .then(() => res.json((0, functions_1.success)({ url: `/backups/${name}.sql` })))+ .catch((err) => res.json((0, functions_1.error)(err.message)));+ }+}+exports.default = CategoriesController;+//# sourceMappingURL=backups.controller.js.map\ No newline at end of filediff --git a/backend/dist/controllers/backups.controller.js.map b/backend/dist/controllers/backups.controller.js.mapnew file mode 100644index 00000000..293e101d--- /dev/null+++ b/backend/dist/controllers/backups.controller.js.map@@ -0,0 +1 @@+{"version":3,"file":"backups.controller.js","sourceRoot":"","sources":["../../controllers/backups.controller.ts"],"names":[],"mappings":";;AAAA,2BAAgE;AAChE,iDAAsC;AAItC,kDAAoD;AAEpD,MAAqB,oBAAoB;IAEvC,YAAY,GAAQ;QADpB;;;;;WAAS;QAEP,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,CAAU,EAAE,GAAa;QACjC,8BAA8B;QAC9B,MAAM,KAAK,GAAG,IAAA,gBAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC;QAC7D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,IAAA,eAAU,EAAC,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,YAAY,IAAI,EAAE,CAAC,CAAC;SAClF;QACD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvE,MAAM,SAAS,GAAG,IAAA,qBAAK,EAAC,WAAW,EAAE;YACnC,IAAI;YACJ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE;YAC9B,KAAK,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACpC,YAAY;SACb,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAA,sBAAiB,EAAC,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,YAAY,IAAI,MAAM,CAAC,CAAC;QACjF,MAAM,aAAa,GAAG,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnE,SAAS,CAAC,MAAM;iBACb,IAAI,CAAC,OAAO,CAAC;iBACb,EAAE,CAAC,QAAQ,EAAE;gBACZ,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC;iBACD,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;gBACxB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QACH,aAAa;aACV,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,mBAAO,EAAC,EAAE,GAAG,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;aAC9D,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,iBAAK,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAnCD,uCAmCC","sourcesContent":["import { createWriteStream, unlinkSync, readdirSync } from 'fs';\nimport { spawn } from 'child_process';\n\nimport type { Request, Response } from 'express';\nimport type { App } from '../app';\nimport { error, success } from '../utils/functions';\n\nexport default class CategoriesController {\n app: App;\n constructor(app: App) {\n this.app = app;\n }\n\n async add(_: Request, res: Response) {\n // Clean the uploads directory\n const files = readdirSync(this.app.uploads_dir + '/backups');\n for (const file of files) {\n if (file.endsWith('.sql')) unlinkSync(`${this.app.uploads_dir}/backups/${file}`);\n }\n const name = new Date().toISOString().split('T')[0] + '-' + Date.now();\n const mysqldump = spawn('mysqldump', [\n '-u',\n `${process.env.DATABASE_USER}`,\n `-p${process.env.DATABASE_PASSWORD}`,\n 'alexandrie',\n ]);\n\n const wstream = createWriteStream(`${this.app.uploads_dir}/backups/${name}.sql`);\n const backupPromise = new Promise<void | string>((resolve, reject) => {\n mysqldump.stdout\n .pipe(wstream)\n .on('finish', function () {\n resolve();\n })\n .on('error', function (err) {\n reject(err.message);\n });\n });\n backupPromise\n .then(() => res.json(success({ url: `/backups/${name}.sql` })))\n .catch((err: Error) => res.json(error(err.message)));\n }\n}\n"]}\ No newline at end of filediff --git a/backend/dist/routes/v1/backup.js b/backend/dist/routes/v1/backup.jsnew file mode 100644index 00000000..c2ffdbb7--- /dev/null+++ b/backend/dist/routes/v1/backup.js@@ -0,0 +1,19 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+const tslib_1 = require("tslib");+const express_1 = require("express");+const backups_controller_1 = tslib_1.__importDefault(require("../../controllers/backups.controller"));+const auth_1 = tslib_1.__importDefault(require("../../middlewares/auth"));+const BackupsRouter = (0, express_1.Router)();+exports.default = (client) => {+ const controller = new backups_controller_1.default(client);+ return {+ route: 'backups',+ version: 1,+ router() {+ BackupsRouter.post('', auth_1.default, (req, res) => controller.add(req, res));+ return BackupsRouter;+ },+ };+};+//# sourceMappingURL=backup.js.map\ No newline at end of filediff --git a/backend/dist/routes/v1/backup.js.map b/backend/dist/routes/v1/backup.js.mapnew file mode 100644index 00000000..1fdbf58e--- /dev/null+++ b/backend/dist/routes/v1/backup.js.map@@ -0,0 +1 @@+{"version":3,"file":"backup.js","sourceRoot":"","sources":["../../../routes/v1/backup.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sGAA+D;AAC/D,0EAA6C;AAI7C,MAAM,aAAa,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEvC,kBAAe,CAAC,MAAW,EAAU,EAAE;IACrC,MAAM,UAAU,GAAG,IAAI,4BAAW,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,CAAC;QACV,MAAM;YACJ,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,cAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACxE,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Router } from 'express';\nimport BackupsCtrl from '../../controllers/backups.controller';\nimport authMid from '../../middlewares/auth';\nimport type { App } from '../../app';\nimport type { Iroute } from '../../types';\n\nconst BackupsRouter: Router = Router();\n\nexport default (client: App): Iroute => {\n const controller = new BackupsCtrl(client);\n return {\n route: 'backups',\n version: 1,\n router() {\n BackupsRouter.post('', authMid, (req, res) => controller.add(req, res));\n return BackupsRouter;\n },\n };\n};\n"]}\ No newline at end of filediff --git a/backend/routes/v1/backup.ts b/backend/routes/v1/backup.tsnew file mode 100644index 00000000..6b77f251--- /dev/null+++ b/backend/routes/v1/backup.ts@@ -0,0 +1,19 @@+import { Router } from 'express';+import BackupsCtrl from '../../controllers/backups.controller';+import authMid from '../../middlewares/auth';+import type { App } from '../../app';+import type { Iroute } from '../../types';++const BackupsRouter: Router = Router();++export default (client: App): Iroute => {+ const controller = new BackupsCtrl(client);+ return {+ route: 'backups',+ version: 1,+ router() {+ BackupsRouter.post('', authMid, (req, res) => controller.add(req, res));+ return BackupsRouter;+ },+ };+};diff --git a/dashboard/components/sidebar/helpers.ts b/dashboard/components/sidebar/helpers.tsindex 46c3ff13..04fc1094 100644--- a/dashboard/components/sidebar/helpers.ts+++ b/dashboard/components/sidebar/helpers.ts@@ -75,6 +75,13 @@ export const defaultItems: Item[] = [route: '/dashboard/cdn',childrens: [],},+ {+ id: 'backup',+ title: 'Backup',+ icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><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>',+ route: '/dashboard/backup',+ childrens: [],+ },],},];diff --git a/dashboard/pages/dashboard.vue b/dashboard/pages/dashboard.vueindex ffd61575..0f033db6 100644--- a/dashboard/pages/dashboard.vue+++ b/dashboard/pages/dashboard.vue@@ -3,6 +3,6 @@<div><Sidebar /></div>- <NuxtPage />+ <NuxtPage style="max-height:100%;overflow: auto;" /></div></template>diff --git a/dashboard/pages/dashboard/backup.vue b/dashboard/pages/dashboard/backup.vuenew file mode 100644index 00000000..3900fd9f--- /dev/null+++ b/dashboard/pages/dashboard/backup.vue@@ -0,0 +1,84 @@+<template>+ <div class="backup-component">+ <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>+ <NuxtLink :href="downloadLink" :download="downloadLink" class="download">Download Backup</NuxtLink>+ </div>+ </div>+</template>++<script setup lang="ts">+import { useNotifications } from '~/store';++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();++ setTimeout(() => {+ isLoading.value = false;+ }, 1000);++ 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">+.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);+ }+}+</style>\ No newline at end of filediff --git a/dashboard/pages/dashboard/cdn.vue b/dashboard/pages/dashboard/cdn.vueindex a718c8ad..4f0aff4d 100644--- a/dashboard/pages/dashboard/cdn.vue+++ b/dashboard/pages/dashboard/cdn.vue@@ -74,25 +74,6 @@ const clearForm = () => selectedFile.value = null;</script><style scoped lang="scss">-.dropzone.drag-over {- background-color: #E3F2FD;- border-color: #2196F3;- transition: background-color 0.3s, border-color 0.3s;-}--.file-info {- display: flex;- flex-direction: column;- align-items: center;- color: #2196F3;-}--.file-size {- font-size: 0.8rem;- color: #757575;- margin-top: 5px;-}-.cdn-component {display: flex;flex-direction: column;@@ -103,69 +84,86 @@ const clearForm = () => selectedFile.value = null;width: 100%;margin: 0 auto;box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);-}--.dropzone {- display: flex;- align-items: center;- justify-content: center;- width: 100%;- height: 150px;- border: 2px dashed #9e9e9e;- border-radius: 4px;- font-size: 14px;- color: #9e9e9e;- position: relative;- transition: background-color 0.2s;- background-color: var(--dropzone-bg, transparent);--}-.dropzone:hover {- background-color: var(--bg-contrast);-}+ .dropzone {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 100%;+ height: 150px;+ border: 2px dashed #9e9e9e;+ border-radius: 4px;+ font-size: 14px;+ color: #9e9e9e;+ position: relative;+ transition: background-color 0.2s;+ background-color: var(--dropzone-bg, transparent);++ &:hover {+ background-color: var(--bg-contrast);+ }++ input[type="file"] {+ display: none;+ }+ }-.dropzone input[type="file"] {- display: none;-}+ .file-info {+ display: flex;+ flex-direction: column;+ align-items: center;+ color: #2196F3;+ color: #2196F3;++ .file-size {+ font-size: 0.8rem;+ color: #757575;+ margin-top: 5px;+ }+ }-.clickable {- color: #2196F3;- cursor: pointer;- text-decoration: underline;-}+ .link-section {+ margin-top: 15px;+ display: flex;+ gap: 10px;+ width: 100%;+ display: flex;+ flex-direction: column;+ }+ .loading-spinner {+ border: 5px solid #f3f3f3;+ border-top: 5px solid $primary-400;+ border-radius: 50%;+ width: 50px;+ height: 50px;+ animation: spin 1s linear infinite;+ }+ .clickable {+ color: #2196F3;+ cursor: pointer;+ text-decoration: underline;+ }-.file-info {- color: #2196F3;-}+ @keyframes spin {+ 0% {+ transform: rotate(0deg);+ }-.link-section {- margin-top: 15px;- display: flex;- gap: 10px;- width: 100%;- display: flex;- flex-direction: column;+ 100% {+ transform: rotate(360deg);+ }+ }}-.loading-spinner {- border: 5px solid #f3f3f3;- border-top: 5px solid $primary-400;- border-radius: 50%;- width: 50px;- height: 50px;- animation: spin 1s linear infinite;+.dropzone.drag-over {+ background-color: #E3F2FD;+ border-color: #2196F3;+ transition: background-color 0.3s, border-color 0.3s;}-@keyframes spin {- 0% {- transform: rotate(0deg);- }-- 100% {- transform: rotate(360deg);- }+.file-info {+ color: #2196F3;}</style>\ No newline at end of filediff --git a/uploads/backups/default b/uploads/backups/defaultnew file mode 100644index 00000000..e69de29b