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 cdn deploy system

Smaug673905da66395e6d
diff --git a/.github/workflows/deploy_to_prod.yml b/.github/workflows/deploy_to_prod.yml
index 93b775bb..19ae7569 100755
--- a/.github/workflows/deploy_to_prod.yml
+++ b/.github/workflows/deploy_to_prod.yml
@@ -36,6 +36,16 @@ jobs:
cd frontend
bun run build
+ - name: Set up Go
+ uses: actions/setup-go@v4
+ with:
+ go-version: 1.20 # Change to your desired Go version
+
+ - name: Build Go application
+ run: | # Build the Go application and name it cdn_app
+ cd cdn # Change to your Go application directory
+ GOOS=linux GOARCH=amd64 go build -o cdn_app
+
- name: Set up SSH
run: |
mkdir -p ~/.ssh
@@ -54,18 +64,23 @@ jobs:
run: |
tar -czf frontend.tar.gz frontend/.output frontend/.env.production
tar -czf backend.tar.gz backend/dist backend/package.json backend/bun.lockb
+ tar -czf cdn.tar.gz cdn/cdn_app # Archive the Go application binary
- name: Transfer Archives
run: |
scp -i deploy_key ecosystem.config.js ${SSH_USER}@"${INPUT_HOST}":"${INPUT_REMOTE}"
scp -i deploy_key frontend.tar.gz ${SSH_USER}@"${INPUT_HOST}":"${INPUT_REMOTE}"
scp -i deploy_key backend.tar.gz ${SSH_USER}@"${INPUT_HOST}":"${INPUT_REMOTE}"
+ scp -i deploy_key cdn.tar.gz ${SSH_USER}@"${INPUT_HOST}":"${INPUT_REMOTE}"
+
- name: Extract Archives on Remote
run: |
- ssh -i deploy_key ${SSH_USER}@"${INPUT_HOST}" "cd ${INPUT_REMOTE} && tar -xzf frontend.tar.gz&& tar -xzf backend.tar.gz && rm frontend.tar.gz"
+ ssh -i deploy_key ${SSH_USER}@"${INPUT_HOST}" "cd ${INPUT_REMOTE} && tar -xzf frontend.tar.gz && tar -xzf backend.tar.gz && tar -xzf cdn.tar.gz && rm frontend.tar.gz backend.tar.gz cdn.tar.gz"
+
- name: Install dependencies for backend
run: |
ssh -i deploy_key ${SSH_USER}@"${INPUT_HOST}" "source ~/.bashrc && cd ${INPUT_REMOTE} && cd backend && bun install --production"
+
- name: Start application
run: |
ssh -i deploy_key ${SSH_USER}@"${INPUT_HOST}" "cd ${INPUT_REMOTE} && NODE_ENV='production' DATABASE_PASSWORD='${{ secrets.DATABASE_PASSWORD }}' DATABASE_USER='${{ secrets.DATABASE_USER }}' JWT_SECRET='${{ secrets.JWT_SECRET }}' pm2 start ecosystem.config.js --update-env"
diff --git a/cdn/cdn_app b/cdn/cdn_app
new file mode 100755
index 00000000..7a6a36ea
Binary files /dev/null and b/cdn/cdn_app differ
diff --git a/cdn/main.go b/cdn/main.go
index 7dd3d7ec..52904340 100644
--- a/cdn/main.go
+++ b/cdn/main.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
+ "os"
"strings"
"github.com/gorilla/handlers"
@@ -11,8 +12,10 @@ import (
)
func main() {
- port := ":3002"
-
+ port := os.Getenv("PORT")
+ if port == "" {
+ port = "3002"
+ }
r := mux.NewRouter()
fileHandler := http.FileServer(http.Dir("../uploads"))
diff --git a/ecosystem.config.js b/ecosystem.config.js
index b20dde8d..b9b32f49 100644
--- a/ecosystem.config.js
+++ b/ecosystem.config.js
@@ -1,26 +1,35 @@
module.exports = {
apps: [
{
- name: "alexandrie-backend",
- cwd: "./backend/dist",
- script: "bun main.js",
+ name: 'alexandrie-backend',
+ cwd: './backend/dist',
+ script: 'bun main.js',
env: {
- NODE_ENV: "production",
+ NODE_ENV: 'production',
PORT: 8201,
- DOMAIN_CLIENT: "https://alexandrie-hub.fr",
+ DOMAIN_CLIENT: 'https://alexandrie-hub.fr',
//DOMAIN_DASHBOARD: "https://dashboard.alexandrie-hub.fr",
- FRONT_DOMAIN: "alexandrie-hub.fr",
+ FRONT_DOMAIN: 'alexandrie-hub.fr',
},
},
{
- name: "alexandrie-frontend",
- cwd: "./frontend",
- script: "bun .output/server/index.mjs",
+ name: 'alexandrie-frontend',
+ cwd: './frontend',
+ script: 'bun .output/server/index.mjs',
env: {
- NODE_ENV: "production",
+ NODE_ENV: 'production',
PORT: 8200,
},
},
+ {
+ name: 'alexandrie-cdn',
+ cwd: './cdn',
+ script: './cdn_app',
+ env: {
+ NODE_ENV: 'production',
+ PORT: 8203,
+ },
+ },
/*{
name: "alexandrie-dashboard",
cwd: "./dashboard",
diff --git a/frontend/.env.development b/frontend/.env.development
index 55cc6a27..a19d10e0 100644
--- a/frontend/.env.development
+++ b/frontend/.env.development
@@ -1,2 +1,2 @@
VITE_BASE_API="http://192.168.0.25:3001"
-VITE_BASE_CDN="http://192.168.0.25:3001"
\ No newline at end of file
+VITE_BASE_CDN="http://192.168.0.25:3002"
\ No newline at end of file
diff --git a/frontend/composables/utils.ts b/frontend/composables/utils.ts
index b00d3b4d..49ddae77 100644
--- a/frontend/composables/utils.ts
+++ b/frontend/composables/utils.ts
@@ -1,4 +1,7 @@
-const CDN = `${import.meta.env.VITE_BASE_API}/static`;
+import type { User } from '../stores/db_strustures';
+
+export const CDN = import.meta.env.VITE_BASE_CDN;
+const API = `${import.meta.env.VITE_BASE_API}/api/v1`;
const colors = ['var(--blue)', 'var(--turquoise)', 'var(--yellow)', 'var(--red)', 'var(--red)'];
@@ -15,7 +18,7 @@ export function useColorHash(str: string): string {
export interface APIResult<Data> {
status: 'success' | 'error';
- message?: string;
+ message: string;
result?: Data;
}
@@ -24,12 +27,10 @@ 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 { 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}`, {
+ const response = await fetch(`${API}/${route}`, {
method: method,
body: method === 'GET' || method === 'DELETE' ? null : body instanceof FormData ? body : JSON.stringify(body),
headers: body instanceof FormData ? {} : { 'Content-Type': 'application/json; charset=UTF-8' },
@@ -106,8 +107,5 @@ export function parseUserAgent(uaString?: string) {
}
}
- return {
- os: os,
- browser: browser,
- };
+ return { os, browser };
}
diff --git a/frontend/pages/dashboard/backup.vue b/frontend/pages/dashboard/backup.vue
index d8460a18..af9fd301 100644
--- a/frontend/pages/dashboard/backup.vue
+++ b/frontend/pages/dashboard/backup.vue
@@ -1,16 +1,16 @@
<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>
+ <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">
@@ -19,63 +19,56 @@ import { useNotifications } from '~/stores';
const downloadLink = ref<string | null>(null);
const copyLink = () => navigator.clipboard.writeText(downloadLink.value!);
const isLoading = ref(false);
-definePageMeta({ breadcrumb: 'Backup' });
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}`;
+ isLoading.value = true;
+ const result = await makeRequest<{ url: string }>('backups', 'POST', {});
+ isLoading.value = false;
+ if (result.status != 'success') {
+ return useNotifications().add({ type: 'error', title: 'Error', message: result.message, timeout: 5000 });
+ }
+ downloadLink.value = `${CDN}/${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;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 2rem;
+ margin: 0 auto;
+ height: min-content;
- h2 {
- margin-bottom: 1rem;
- }
+ h2 {
+ margin-bottom: 1rem;
+ }
- input {
- margin-bottom: 1rem;
- }
+ input {
+ margin-bottom: 1rem;
+ }
- .download {
- margin-left: 15px;
- }
+ .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;
+ 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);
- }
+ 0% {
+ transform: rotate(0deg);
+ }
- 100% {
- transform: rotate(360deg);
- }
+ 100% {
+ transform: rotate(360deg);
+ }
}
-</style>
\ No newline at end of file
+</style>
diff --git a/frontend/pages/dashboard/cdn.vue b/frontend/pages/dashboard/cdn.vue
index f02817e8..65f703f9 100644
--- a/frontend/pages/dashboard/cdn.vue
+++ b/frontend/pages/dashboard/cdn.vue
@@ -1,30 +1,25 @@
<template>
- <div class="cdn-component">
- <h2>CDN: File manager</h2>
- <div class="dropzone" :class="{ 'drag-over': isDragOver }" @dragover.prevent @drop.prevent="handleFileDrop"
- @dragenter.prevent="dragEnter" @dragleave.prevent="dragLeave">
- <input type="file" ref="fileInput" @change="handleFileSelect" />
- <div v-if="selectedFile" class="file-info">
- <span>{{ selectedFile.name }}</span>
- <div class="file-size">{{ readableFileSize(selectedFile.size) }}</div>
- </div>
- <div v-else>
- Drop file here or <span class="clickable" @click="triggerFileSelect">click to select from computed</span>.
- </div>
- </div>
- <button @click="submitFile" :disabled="!selectedFile">Upload on server</button>
- <div v-if="isLoading" class="loading-spinner"></div>
- <div v-if="fileLink" class="link-section">
- <input type="text" v-model="fileLink" readonly />
- <button @click="copyLink">Copy link</button>
- </div>
- <div v-if="ressources.length" class="ressources-list">
- <DataTable :headers="headers" :rows="rows" />
- </div>
- <div v-else>
- No ressource found.
- </div>
- </div>
+ <div class="cdn-component">
+ <h2>CDN: File manager</h2>
+ <div class="dropzone" :class="{ 'drag-over': isDragOver }" @dragover.prevent @drop.prevent="handleFileDrop" @dragenter.prevent="dragEnter" @dragleave.prevent="dragLeave">
+ <input type="file" ref="fileInput" @change="handleFileSelect" />
+ <div v-if="selectedFile" class="file-info">
+ <span>{{ selectedFile.name }}</span>
+ <div class="file-size">{{ readableFileSize(selectedFile.size) }}</div>
+ </div>
+ <div v-else>Drop file here or <span class="clickable" @click="triggerFileSelect">click to select from computed</span>.</div>
+ </div>
+ <button @click="submitFile" :disabled="!selectedFile">Upload on server</button>
+ <div v-if="isLoading" class="loading-spinner"></div>
+ <div v-if="fileLink" class="link-section">
+ <input type="text" v-model="fileLink" readonly />
+ <button @click="copyLink">Copy link</button>
+ </div>
+ <div v-if="ressources.length" class="ressources-list">
+ <DataTable :headers="headers" :rows="rows" />
+ </div>
+ <div v-else>No ressource found.</div>
+ </div>
</template>
<script setup lang="ts">
import { useNotifications, useRessourcesStore, type DB_Ressource } from '~/stores';
@@ -38,157 +33,159 @@ const fileInput: Ref<HTMLInputElement | null> = ref(null);
const isLoading = ref(false);
const ressources = ressourcesStore.ressources;
const triggerFileSelect = () => fileInput.value!.click();
-const handleFileSelect = (event: Event) => selectedFile.value = (event.target as HTMLInputElement | null)?.files?.[0] || null;
+const handleFileSelect = (event: Event) => (selectedFile.value = (event.target as HTMLInputElement | null)?.files?.[0] || null);
definePageMeta({ breadcrumb: 'CDN' });
const handleFileDrop = (event: DragEvent) => {
- if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) {
- selectedFile.value = event.dataTransfer.files[0];
- isDragOver.value = false;
- }
-}
+ if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) {
+ selectedFile.value = event.dataTransfer.files[0];
+ isDragOver.value = false;
+ }
+};
const copyLink = () => navigator.clipboard.writeText(fileLink.value!);
-const dragEnter = () => isDragOver.value = true;
-const dragLeave = () => isDragOver.value = false;
+const dragEnter = () => (isDragOver.value = true);
+const dragLeave = () => (isDragOver.value = false);
const submitFile = async () => {
- if (!selectedFile.value) return;
- isLoading.value = true;
+ if (!selectedFile.value) return;
+ isLoading.value = true;
- const body = new FormData();
- body.append("file", selectedFile.value);
- selectedFile.value = null; // Reset selected file
+ const body = new FormData();
+ body.append('file', selectedFile.value);
+ selectedFile.value = null; // Reset selected file
- await ressourcesStore.post(body)
- .then((r) => fileLink.value = `${import.meta.env.VITE_BASE_API}/static${(r as DB_Ressource).transformed_path || (r as DB_Ressource).original_path}`)
- .catch((e) => useNotifications().add({ type: "error", title: "Error", message: e, timeout: 5000 }))
- .finally(() => isLoading.value = false);
-}
+ await ressourcesStore
+ .post(body)
+ .then(r => (fileLink.value = `${CDN}/${(r as DB_Ressource).transformed_path || (r as DB_Ressource).original_path}`))
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e, timeout: 5000 }))
+ .finally(() => (isLoading.value = false));
+};
const readableFileSize = (size: number): string => {
- const i = Math.floor(Math.log(size) / Math.log(1024));
- return `${(size / Math.pow(1024, i)).toFixed(2)} ${["B", "kB", "MB", "GB", "TB"][i]}`
-}
+ const i = Math.floor(Math.log(size) / Math.log(1024));
+ return `${(size / Math.pow(1024, i)).toFixed(2)} ${['B', 'kB', 'MB', 'GB', 'TB'][i]}`;
+};
const headers = [
- { label: 'Name', key: 'name' },
- { label: 'Size', key: 'size' },
- { label: 'Type', key: 'type' },
- { label: 'Date', key: 'date' },
- { label: 'Action', key: 'action' },
+ { label: 'Name', key: 'name' },
+ { label: 'Size', key: 'size' },
+ { label: 'Type', key: 'type' },
+ { label: 'Date', key: 'date' },
+ { label: 'Action', key: 'action' },
];
-const color = (type: string) => type.includes('image') ? 'green' : type.includes('video') ? 'blue' : type.includes('pdf') ? 'yellow' : 'red';
-const rows: any = computed(() => ressources.map((res) => {
- return {
- name: { content: res.filename },
- size: { content: readableFileSize(res.file_size) },
- type: { content: `<span class="tag ${color(res.file_type)}">${res.file_type}</span>`, type: 'html' },
- date: { content: new Date(res.created_timestamp).toLocaleDateString() },
- action: { content: `<a href="${import.meta.env.VITE_BASE_API}/static${res.transformed_path || res.original_path}" target="_blank">View</a>`, type: 'html' },
- };
-}));
-
+const color = (type: string) => (type.includes('image') ? 'green' : type.includes('video') ? 'blue' : type.includes('pdf') ? 'yellow' : 'red');
+const rows: any = computed(() =>
+ ressources.map(res => {
+ return {
+ name: { content: res.filename },
+ size: { content: readableFileSize(res.file_size) },
+ type: { content: `<span class="tag ${color(res.file_type)}">${res.file_type}</span>`, type: 'html' },
+ date: { content: new Date(res.created_timestamp).toLocaleDateString() },
+ action: { content: `<a href="${CDN}/${res.transformed_path || res.original_path}" target="_blank">View</a>`, type: 'html' },
+ };
+ }),
+);
</script>
<style scoped lang="scss">
.cdn-component {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 1.5rem;
- padding: 2rem;
- border-radius: 8px;
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 1.5rem;
+ padding: 2rem;
+ border-radius: 8px;
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
button {
- background-color: var(--font-color);
- color: var(--bg-color);
+ background-color: var(--font-color);
+ color: var(--bg-color);
}
h2 {
- margin: 0;
+ margin: 0;
}
.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 $transition-duration;
- background-color: var(--dropzone-bg, transparent);
-
- &:hover {
- background-color: var(--bg-contrast);
- }
-
- input[type="file"] {
- display: none;
- }
+ 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 $transition-duration;
+ background-color: var(--dropzone-bg, transparent);
+
+ &:hover {
+ background-color: var(--bg-contrast);
+ }
+
+ input[type='file'] {
+ display: none;
+ }
}
.drag-over {
- background-color: #E3F2FD;
- border-color: #2196F3;
- transition: background-color $transition-duration, border-color $transition-duration;
+ background-color: #e3f2fd;
+ border-color: #2196f3;
+ transition: background-color $transition-duration, border-color $transition-duration;
}
.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;
- }
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ color: #2196f3;
+ color: #2196f3;
+
+ .file-size {
+ font-size: 0.8rem;
+ color: #757575;
+ margin-top: 5px;
+ }
}
.link-section {
- margin-top: 15px;
- display: flex;
- gap: 10px;
- width: 100%;
- display: flex;
- flex-direction: column;
+ 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;
+ 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;
+ color: #2196f3;
+ cursor: pointer;
+ text-decoration: underline;
}
@keyframes spin {
- 0% {
- transform: rotate(0deg);
- }
+ 0% {
+ transform: rotate(0deg);
+ }
- 100% {
- transform: rotate(360deg);
- }
+ 100% {
+ transform: rotate(360deg);
+ }
}
.file-info {
- color: #2196F3;
+ color: #2196f3;
}
</style>
diff --git a/frontend/pages/dashboard/settings.vue b/frontend/pages/dashboard/settings.vue
index d74e211b..f024a112 100644
--- a/frontend/pages/dashboard/settings.vue
+++ b/frontend/pages/dashboard/settings.vue
@@ -162,17 +162,12 @@ 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();
+ const result = await makeRequest<{ url: string }>('backups', 'POST', {});
isLoading.value = false;
if (result.status != 'success') {
- useNotifications().add({ type: 'error', title: 'Error', message: result.message, timeout: 5000 });
- return;
+ return useNotifications().add({ type: 'error', title: 'Error', message: result.message, timeout: 5000 });
}
- downloadLink.value = `${import.meta.env.VITE_BASE_API}/static${result.result.url}`;
+ downloadLink.value = `${CDN}/${result.result?.url || ''}`;
}
</script>