feat: ability to delete s3 objects, make endpoint an env #2

Merged
naomi merged 2 commits from feat/s3 into main 2026-02-02 10:58:45 -08:00
5 changed files with 25 additions and 4 deletions
Showing only changes of commit 140d0fd624 - Show all commits
+1
View File
@@ -15,6 +15,7 @@ DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Amari/bot token"
# AWS # AWS
AWS_ACCESS_KEY_ID="op://Private/Hetzner/S3 Access Key ID" AWS_ACCESS_KEY_ID="op://Private/Hetzner/S3 Access Key ID"
AWS_SECRET_ACCESS_KEY="op://Private/Hetzner/S3 Secret Access Key" AWS_SECRET_ACCESS_KEY="op://Private/Hetzner/S3 Secret Access Key"
S3_ENDPOINT="op://Private/Hetzner/S3 Endpoint"
# Gitea # Gitea
GITEA_TOKEN="op://Private/Gitea/token" GITEA_TOKEN="op://Private/Gitea/token"
+6 -1
View File
@@ -12,11 +12,16 @@ import { getMimeType } from "../utils/mimeType.js";
const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const endpoint = process.env.S3_ENDPOINT;
if (accessKeyId === undefined || secretAccessKey === undefined) { if (accessKeyId === undefined || secretAccessKey === undefined) {
throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); 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"); const dataDirectory = join(import.meta.dirname, "..", "..", "data");
/** /**
@@ -172,7 +177,7 @@ if (!shouldProceed) {
const s3 = new S3Client({ const s3 = new S3Client({
credentials: { accessKeyId, secretAccessKey }, credentials: { accessKeyId, secretAccessKey },
endpoint: "https://hel1.your-objectstorage.com", endpoint: endpoint,
region: "hel1", region: "hel1",
}); });
+6 -1
View File
@@ -15,6 +15,7 @@ import { getMimeType } from "../utils/mimeType.js";
const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const endpoint = process.env.S3_ENDPOINT;
if (accessKeyId === undefined || secretAccessKey === undefined) { if (accessKeyId === undefined || secretAccessKey === undefined) {
throw new Error( 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({ const s3 = new S3Client({
credentials: { accessKeyId, secretAccessKey }, credentials: { accessKeyId, secretAccessKey },
endpoint: "https://hel1.your-objectstorage.com", endpoint: endpoint,
region: "hel1", region: "hel1",
}); });
+6 -1
View File
@@ -12,11 +12,16 @@ import { SingleBar, Presets } from "cli-progress";
const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const endpoint = process.env.S3_ENDPOINT;
if (accessKeyId === undefined || secretAccessKey === undefined) { if (accessKeyId === undefined || secretAccessKey === undefined) {
throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); 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 // Get bucket name
const bucketName = await input({ const bucketName = await input({
message: "Enter the S3 bucket name:", message: "Enter the S3 bucket name:",
@@ -35,7 +40,7 @@ const bucketName = await input({
// Create S3 client // Create S3 client
const s3 = new S3Client({ const s3 = new S3Client({
credentials: { accessKeyId, secretAccessKey }, credentials: { accessKeyId, secretAccessKey },
endpoint: "https://hel1.your-objectstorage.com", endpoint: endpoint,
region: "hel1", region: "hel1",
}); });
+6 -1
View File
@@ -11,11 +11,16 @@ import { getMimeType } from "../utils/mimeType.js";
const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const endpoint = process.env.S3_ENDPOINT;
if (accessKeyId === undefined || secretAccessKey === undefined) { if (accessKeyId === undefined || secretAccessKey === undefined) {
throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set"); 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({ const fileName = await input({
message: message:
// eslint-disable-next-line stylistic/max-len -- Big boi string. // eslint-disable-next-line stylistic/max-len -- Big boi string.
@@ -40,7 +45,7 @@ if (uploadPath === "") {
const s3 = new S3Client({ const s3 = new S3Client({
credentials: { accessKeyId, secretAccessKey }, credentials: { accessKeyId, secretAccessKey },
endpoint: "https://hel1.your-objectstorage.com", endpoint: endpoint,
region: "hel1", region: "hel1",
}); });