BODY_SIZE_LIMIT fix, database url encode

This commit is contained in:
Wayne
2025-08-13 21:55:22 +03:00
parent d2b4337be9
commit 82a83a71e4
6 changed files with 38 additions and 22 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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 });

View File

@@ -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...');

View File

@@ -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");
}
};

View File

@@ -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()
}
};