From 140d0fd62411ef073090881faf3d545fdc0349f4 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Mon, 2 Feb 2026 10:21:12 -0800 Subject: [PATCH] feat: make endpoint an env instead of hardcoded --- prod.env | 1 + typescript/src/s3/bulkUpload.ts | 7 ++++++- typescript/src/s3/correctContentType.ts | 7 ++++++- typescript/src/s3/deleteContents.ts | 7 ++++++- typescript/src/s3/upload.ts | 7 ++++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/prod.env b/prod.env index 1ac9dcd..b9961d6 100644 --- a/prod.env +++ b/prod.env @@ -15,6 +15,7 @@ DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Amari/bot token" # AWS AWS_ACCESS_KEY_ID="op://Private/Hetzner/S3 Access Key ID" AWS_SECRET_ACCESS_KEY="op://Private/Hetzner/S3 Secret Access Key" +S3_ENDPOINT="op://Private/Hetzner/S3 Endpoint" # Gitea GITEA_TOKEN="op://Private/Gitea/token" diff --git a/typescript/src/s3/bulkUpload.ts b/typescript/src/s3/bulkUpload.ts index 77b8b1d..c7ef695 100644 --- a/typescript/src/s3/bulkUpload.ts +++ b/typescript/src/s3/bulkUpload.ts @@ -12,11 +12,16 @@ import { getMimeType } from "../utils/mimeType.js"; const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; +const endpoint = process.env.S3_ENDPOINT; if (accessKeyId === undefined || secretAccessKey === undefined) { throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); } +if (endpoint === undefined) { + throw new Error("S3_ENDPOINT is not set"); +} + const dataDirectory = join(import.meta.dirname, "..", "..", "data"); /** @@ -172,7 +177,7 @@ if (!shouldProceed) { const s3 = new S3Client({ credentials: { accessKeyId, secretAccessKey }, - endpoint: "https://hel1.your-objectstorage.com", + endpoint: endpoint, region: "hel1", }); diff --git a/typescript/src/s3/correctContentType.ts b/typescript/src/s3/correctContentType.ts index 9961326..29a8824 100644 --- a/typescript/src/s3/correctContentType.ts +++ b/typescript/src/s3/correctContentType.ts @@ -15,6 +15,7 @@ import { getMimeType } from "../utils/mimeType.js"; const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; +const endpoint = process.env.S3_ENDPOINT; if (accessKeyId === undefined || secretAccessKey === undefined) { throw new Error( @@ -22,9 +23,13 @@ if (accessKeyId === undefined || secretAccessKey === undefined) { ); } +if (endpoint === undefined) { + throw new Error("S3_ENDPOINT is not set"); +} + const s3 = new S3Client({ credentials: { accessKeyId, secretAccessKey }, - endpoint: "https://hel1.your-objectstorage.com", + endpoint: endpoint, region: "hel1", }); diff --git a/typescript/src/s3/deleteContents.ts b/typescript/src/s3/deleteContents.ts index 5f8df94..a145600 100644 --- a/typescript/src/s3/deleteContents.ts +++ b/typescript/src/s3/deleteContents.ts @@ -12,11 +12,16 @@ import { SingleBar, Presets } from "cli-progress"; const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; +const endpoint = process.env.S3_ENDPOINT; if (accessKeyId === undefined || secretAccessKey === undefined) { throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); } +if (endpoint === undefined) { + throw new Error("S3_ENDPOINT is not set"); +} + // Get bucket name const bucketName = await input({ message: "Enter the S3 bucket name:", @@ -35,7 +40,7 @@ const bucketName = await input({ // Create S3 client const s3 = new S3Client({ credentials: { accessKeyId, secretAccessKey }, - endpoint: "https://hel1.your-objectstorage.com", + endpoint: endpoint, region: "hel1", }); diff --git a/typescript/src/s3/upload.ts b/typescript/src/s3/upload.ts index c814d98..d046285 100644 --- a/typescript/src/s3/upload.ts +++ b/typescript/src/s3/upload.ts @@ -11,11 +11,16 @@ import { getMimeType } from "../utils/mimeType.js"; const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; +const endpoint = process.env.S3_ENDPOINT; if (accessKeyId === undefined || secretAccessKey === undefined) { throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); } +if (endpoint === undefined) { + throw new Error("S3_ENDPOINT is not set"); +} + const fileName = await input({ message: // eslint-disable-next-line stylistic/max-len -- Big boi string. @@ -40,7 +45,7 @@ if (uploadPath === "") { const s3 = new S3Client({ credentials: { accessKeyId, secretAccessKey }, - endpoint: "https://hel1.your-objectstorage.com", + endpoint: endpoint, region: "hel1", });