diff --git a/.env.example b/.env.example index cab25c4..1ac9bcd 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ RATE_LIMIT_MAX_REQUESTS=30 # TRUST_PROXY=true # Uncomment when behind reverse proxy (Traefik, Nginx) for correct client IP detection # S3-compatible API credentials -# S3_ACCESS_KEY=teleuploader-admin +# S3_ACCESS_KEY=filedrop-admin # S3_SECRET_KEY=your-secret-key-here # S3_DEFAULT_REGION=us-east-1 # S3_VHOST_DOMAINS=upload.asepharyana.my.id,upload.asepharyana.web.id @@ -19,4 +19,11 @@ RATE_LIMIT_MAX_REQUESTS=30 # Telegram-safe internal chunking for large stored files # TELEGRAM_CHUNK_SIZE_BYTES=20971520 # COMPRESS_CHUNKED_UPLOADS=true -# CHUNK_COMPRESSION_MIN_SIZE_BYTES=4096 \ No newline at end of file +# CHUNK_COMPRESSION_MIN_SIZE_BYTES=4096 + +# Web dashboard/API auth. If empty, dashboard remains public. +ADMIN_API_TOKEN= + +# Optional session cookie settings +# SESSION_COOKIE_NAME=tu_session +# SESSION_COOKIE_MAX_AGE_SECONDS=86400 \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 835ee0b..6538e6f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ #!/bin/bash -# ─── TeleUploader Deploy Script ────────────────────────────────────────────── +# ─── FileDrop Deploy Script ────────────────────────────────────────────────── # Builds the Bun app locally and deploys to the VPS via Docker. # # Strategy: build dist locally, ship dist + Docker context to VPS via tar pipe, @@ -22,14 +22,14 @@ # VPS_SSH_KEY — path/contents of SSH private key # # Optional: -# DEPLOY_DIR — deploy dir on VPS (default: /opt/teleuploader) +# DEPLOY_DIR — deploy dir on VPS (default: /opt/filedrop) # ADMIN_PASSWORD — verify health after deploy (optional) # ────────────────────────────────────────────────────────────────────────────── set -eu # ── Config ──────────────────────────────────────────────────────────────────── -APP_NAME="teleuploader" +APP_NAME="filedrop" GITLAB_PROJECT="superaseph%2FTeleUploader" DEPLOY_DIR="${DEPLOY_DIR:-/opt/${APP_NAME}}" COMPOSE_FILE="docker-compose.yml" diff --git a/docker-compose.yml b/docker-compose.yml index 929f44d..8e52258 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: app: build: . - container_name: teleuploader-app + container_name: filedrop-app restart: always environment: - BOT_TOKEN=${BOT_TOKEN} @@ -22,7 +22,10 @@ services: - CHUNK_COMPRESSION_MIN_SIZE_BYTES=${CHUNK_COMPRESSION_MIN_SIZE_BYTES:-4096} - RATE_LIMIT_WINDOW_MS=${RATE_LIMIT_WINDOW_MS:-60000} - RATE_LIMIT_MAX_REQUESTS=${RATE_LIMIT_MAX_REQUESTS:-30} - - S3_ACCESS_KEY=${S3_ACCESS_KEY:-teleuploader-admin} + - ADMIN_API_TOKEN=${ADMIN_API_TOKEN:-} + - SESSION_COOKIE_NAME=${SESSION_COOKIE_NAME:-tu_session} + - SESSION_COOKIE_MAX_AGE_SECONDS=${SESSION_COOKIE_MAX_AGE_SECONDS:-86400} + - S3_ACCESS_KEY=${S3_ACCESS_KEY:-filedrop-admin} - S3_SECRET_KEY=${S3_SECRET_KEY} - S3_DEFAULT_REGION=${S3_DEFAULT_REGION:-us-east-1} - S3_VHOST_DOMAINS=${S3_VHOST_DOMAINS:-upload.asepharyana.my.id,asepharyana.web.id} @@ -52,16 +55,16 @@ services: - app-shared-net labels: - "traefik.enable=true" - - "traefik.http.routers.teleuploader.rule=Host(`upload.asepharyana.my.id`) || Host(`upload.asepharyana.web.id`) || Host(`asepharyana.web.id`) || HostRegexp(`{subhost:[a-z0-9][a-z0-9.-]+}.asepharyana.web.id`)" - - "traefik.http.routers.teleuploader.entrypoints=websecure" - - "traefik.http.routers.teleuploader.tls=true" - - "traefik.http.routers.teleuploader.tls.certresolver=cloudflare" - - "traefik.http.services.teleuploader.loadbalancer.server.port=3000" - - "traefik.http.middlewares.teleuploader-rl.ratelimit.average=300" - - "traefik.http.middlewares.teleuploader-rl.ratelimit.burst=100" - - "traefik.http.middlewares.teleuploader-rl.ratelimit.period=1m" - - "traefik.http.middlewares.teleuploader-buf.buffering.maxRequestBodyBytes=2147483648" - - "traefik.http.routers.teleuploader.middlewares=teleuploader-rl@docker,teleuploader-buf@docker" + - "traefik.http.routers.filedrop.rule=Host(`upload.asepharyana.my.id`) || Host(`upload.asepharyana.web.id`) || Host(`asepharyana.web.id`) || HostRegexp(`{subhost:[a-z0-9][a-z0-9.-]+}.asepharyana.web.id`)" + - "traefik.http.routers.filedrop.entrypoints=websecure" + - "traefik.http.routers.filedrop.tls=true" + - "traefik.http.routers.filedrop.tls.certresolver=cloudflare" + - "traefik.http.services.filedrop.loadbalancer.server.port=3000" + - "traefik.http.middlewares.filedrop-rl.ratelimit.average=300" + - "traefik.http.middlewares.filedrop-rl.ratelimit.burst=100" + - "traefik.http.middlewares.filedrop-rl.ratelimit.period=1m" + - "traefik.http.middlewares.filedrop-buf.buffering.maxRequestBodyBytes=2147483648" + - "traefik.http.routers.filedrop.middlewares=filedrop-rl@docker,filedrop-buf@docker" networks: app-shared-net: diff --git a/package.json b/package.json index 14a0d1e..4b7f4de 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "teleuploader", + "name": "filedrop", "version": "1.0.0", "description": "Telegram file uploader backend", "type": "module", @@ -8,7 +8,7 @@ "build": "bun build src/index.ts --target=bun --outfile=dist/index.js && bun build src/db/migrate.ts --target=bun --outfile=dist/migrate.js", "start": "NODE_ENV=production bun dist/index.js", "db:migrate": "bun dist/migrate.js", - "test": "bun test test/rateLimit.test.ts && bun test test/file.test.ts && bun test test/telegram.test.ts && bun test test/upload.test.ts && bun test test/files.test.ts && bun test test/health.test.ts && bun test test/db.test.ts && bun test test/bot.test.ts && bun test test/bootstrap.test.ts && bun test test/swagger.test.ts && bun test test/s3-auth.test.ts && bun test test/s3-operations.test.ts && bun test test/web-api.test.ts", + "test": "bun test test/rateLimit.test.ts && bun test test/file.test.ts && bun test test/telegram.test.ts && bun test test/upload.test.ts && bun test test/files.test.ts && bun test test/health.test.ts && bun test test/db.test.ts && bun test test/bot.test.ts && bun test test/bootstrap.test.ts && bun test test/swagger.test.ts && bun test test/auth.test.ts && bun test test/auth-routes.test.ts && bun test test/s3-auth.test.ts && bun test test/s3-operations.test.ts && bun test test/s3-bucket-config.test.ts && bun test test/web-api.test.ts", "test:s3-auth": "bun test test/s3-auth.test.ts", "test:s3-ops": "bun test test/s3-operations.test.ts", "test:web-api": "bun test test/web-api.test.ts", diff --git a/src/env.ts b/src/env.ts index 43b6400..09d874c 100644 --- a/src/env.ts +++ b/src/env.ts @@ -19,6 +19,9 @@ interface AppConfig { telegramChunkSizeBytes: number; compressChunkedUploads: boolean; chunkCompressionMinSizeBytes: number; + adminApiToken: string; + sessionCookieName: string; + sessionMaxAgeMs: number; s3AccessKey: string; s3SecretKey: string; s3DefaultRegion: string; @@ -91,7 +94,10 @@ export const config: AppConfig = { telegramChunkSizeBytes: parseNumber(process.env.TELEGRAM_CHUNK_SIZE_BYTES, 20 * 1024 * 1024), compressChunkedUploads: process.env.COMPRESS_CHUNKED_UPLOADS !== 'false', chunkCompressionMinSizeBytes: parseNumber(process.env.CHUNK_COMPRESSION_MIN_SIZE_BYTES, 4096), - s3AccessKey: process.env.S3_ACCESS_KEY || 'teleuploader-admin', + adminApiToken: process.env.ADMIN_API_TOKEN || '', + sessionCookieName: process.env.SESSION_COOKIE_NAME || 'tu_session', + sessionMaxAgeMs: parseNumber(process.env.SESSION_COOKIE_MAX_AGE_SECONDS, 86400) * 1000, + s3AccessKey: process.env.S3_ACCESS_KEY || 'filedrop-admin', s3SecretKey: process.env.S3_SECRET_KEY || '', s3DefaultRegion: process.env.S3_DEFAULT_REGION || 'us-east-1', proxyS3Get: process.env.PROXY_S3_GET !== 'false', @@ -107,6 +113,8 @@ logger.info('Environment variables loaded', { botToken: maskSecret(config.botToken), additionalBotTokens: config.additionalBotTokens.map(maskSecret), databaseUrl: maskDatabaseUrl(config.databaseUrl), + adminApiToken: maskSecret(config.adminApiToken), + adminApiTokenEnabled: config.adminApiToken.length > 0, s3AccessKey: maskSecret(config.s3AccessKey), s3SecretKey: maskSecret(config.s3SecretKey), }, diff --git a/src/home.html b/src/home.html index ad6ab81..f807e81 100644 --- a/src/home.html +++ b/src/home.html @@ -3,7 +3,7 @@
-Enter admin token to continue.
+ + + +