diff --git a/.env.example b/.env.example index ed0d4a0..a7a243d 100644 --- a/.env.example +++ b/.env.example @@ -34,7 +34,7 @@ REDIS_TLS_ENABLED=false # Choose your storage backend. Valid options are 'local' or 's3'. STORAGE_TYPE=local # The maximum request body size to accept in bytes including while streaming. The body size can also be specified with a unit suffix for kilobytes (K), megabytes (M), or gigabytes (G). For example, 512K or 1M. Defaults to 512kb. Or the value of Infinity if you don't want any upload limit. -FRONTEND_BODY_SIZE_LIMIT=100M +BODY_SIZE_LIMIT=100M # --- Local Storage Settings --- # The path inside the container where files will be stored. diff --git a/docs/user-guides/installation.md b/docs/user-guides/installation.md index 4bac769..7b26955 100644 --- a/docs/user-guides/installation.md +++ b/docs/user-guides/installation.md @@ -65,11 +65,12 @@ Here is a complete list of environment variables available for configuration: #### Application Settings -| Variable | Description | Default Value | -| --------------- | ---------------------------------- | ------------- | -| `NODE_ENV` | The application environment. | `development` | -| `PORT_BACKEND` | The port for the backend service. | `4000` | -| `PORT_FRONTEND` | The port for the frontend service. | `3000` | +| Variable | Description | Default Value | +| ---------------- | ----------------------------------------------------------------------------------------------------- | ------------- | +| `NODE_ENV` | The application environment. | `development` | +| `PORT_BACKEND` | The port for the backend service. | `4000` | +| `PORT_FRONTEND` | The port for the frontend service. | `3000` | +| `SYNC_FREQUENCY` | The frequency of continuous email syncing. See [cron syntax](https://crontab.guru/) for more details. | `* * * * *` | #### Docker Compose Service Configuration @@ -90,16 +91,17 @@ These variables are used by `docker-compose.yml` to configure the services. #### Storage Settings -| Variable | Description | Default Value | -| ------------------------------ | ------------------------------------------------------------------------------------- | ------------------------- | -| `STORAGE_TYPE` | The storage backend to use (`local` or `s3`). | `local` | -| `STORAGE_LOCAL_ROOT_PATH` | The root path for local file storage. | `/var/data/open-archiver` | -| `STORAGE_S3_ENDPOINT` | The endpoint for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | -| `STORAGE_S3_BUCKET` | The bucket name for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | -| `STORAGE_S3_ACCESS_KEY_ID` | The access key ID for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | -| `STORAGE_S3_SECRET_ACCESS_KEY` | The secret access key for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | -| `STORAGE_S3_REGION` | The region for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | -| `STORAGE_S3_FORCE_PATH_STYLE` | Force path-style addressing for S3 (optional). | `false` | +| Variable | Description | Default Value | +| ------------------------------ | ----------------------------------------------------------------------------------------------------------- | ------------------------- | +| `STORAGE_TYPE` | The storage backend to use (`local` or `s3`). | `local` | +| `BODY_SIZE_LIMIT` | The maximum request body size for uploads. Can be a number in bytes or a string with a unit (e.g., `100M`). | `100M` | +| `STORAGE_LOCAL_ROOT_PATH` | The root path for local file storage. | `/var/data/open-archiver` | +| `STORAGE_S3_ENDPOINT` | The endpoint for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | +| `STORAGE_S3_BUCKET` | The bucket name for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | +| `STORAGE_S3_ACCESS_KEY_ID` | The access key ID for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | +| `STORAGE_S3_SECRET_ACCESS_KEY` | The secret access key for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | +| `STORAGE_S3_REGION` | The region for S3-compatible storage (required if `STORAGE_TYPE` is `s3`). | | +| `STORAGE_S3_FORCE_PATH_STYLE` | Force path-style addressing for S3 (optional). | `false` | #### Security & Authentication diff --git a/packages/backend/src/database/index.ts b/packages/backend/src/database/index.ts index aaa0b50..94744b1 100644 --- a/packages/backend/src/database/index.ts +++ b/packages/backend/src/database/index.ts @@ -3,10 +3,12 @@ import postgres from 'postgres'; import 'dotenv/config'; import * as schema from './schema'; +import { encodeDatabaseUrl } from '../helpers/db'; if (!process.env.DATABASE_URL) { throw new Error('DATABASE_URL is not set in the .env file'); } -const client = postgres(process.env.DATABASE_URL); +const connectionString = encodeDatabaseUrl(process.env.DATABASE_URL); +const client = postgres(connectionString); export const db = drizzle(client, { schema }); diff --git a/packages/backend/src/database/migrate.ts b/packages/backend/src/database/migrate.ts index d22dd66..610d960 100644 --- a/packages/backend/src/database/migrate.ts +++ b/packages/backend/src/database/migrate.ts @@ -2,6 +2,7 @@ import { migrate } from 'drizzle-orm/postgres-js/migrator'; import { drizzle } from 'drizzle-orm/postgres-js'; import postgres from 'postgres'; import { config } from 'dotenv'; +import { encodeDatabaseUrl } from '../helpers/db'; config(); @@ -10,7 +11,8 @@ const runMigrate = async () => { throw new Error('DATABASE_URL is not set in the .env file'); } - const connection = postgres(process.env.DATABASE_URL, { max: 1 }); + const connectionString = encodeDatabaseUrl(process.env.DATABASE_URL); + const connection = postgres(connectionString, { max: 1 }); const db = drizzle(connection); console.log('Running migrations...'); diff --git a/packages/backend/src/helpers/db.ts b/packages/backend/src/helpers/db.ts new file mode 100644 index 0000000..f57c50c --- /dev/null +++ b/packages/backend/src/helpers/db.ts @@ -0,0 +1,12 @@ +export const encodeDatabaseUrl = (databaseUrl: string): string => { + try { + const url = new URL(databaseUrl); + if (url.password) { + url.password = encodeURIComponent(url.password); + } + return url.toString(); + } catch (error) { + console.error("Invalid DATABASE_URL, please check your .env file.", error); + throw new Error("Invalid DATABASE_URL"); + } +}; diff --git a/packages/frontend/svelte.config.js b/packages/frontend/svelte.config.js index 4b4f698..0dbd5e5 100644 --- a/packages/frontend/svelte.config.js +++ b/packages/frontend/svelte.config.js @@ -1,15 +1,13 @@ import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; -import 'dotenv/config'; + /** @type {import('@sveltejs/kit').Config} */ const config = { // Consult https://svelte.dev/docs/kit/integrations // for more information about preprocessors preprocess: vitePreprocess(), kit: { - adapter: adapter({ - bodySizeLimit: process.env.FRONTEND_BODY_SIZE_LIMIT || '100M' - }) + adapter: adapter() } };