fix: local regression

replace my hard coded thinking

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-22 11:00:00 +08:00
parent 439bb33f77
commit 3aeb217907
+24 -9
View File
@@ -18,16 +18,30 @@ const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const crypto = require("crypto");
const path = require("path");
// ─── Client ───────────────────────────────────────────────────────────────────
// ─── Clients ──────────────────────────────────────────────────────────────────
const credentials = {
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
};
// Internal client — uploads, deletes, direct streams from the server itself.
const s3 = new S3Client({
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION || "garage",
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
},
forcePathStyle: true, // required — Garage does not support DNS-style bucket addressing
credentials,
forcePathStyle: true,
});
// Public client — generates pre-signed URLs using the externally reachable
// endpoint (S3_PUBLIC_URL) so URLs work from any machine, not just the one
// running Garage. Falls back to the internal endpoint when S3_PUBLIC_URL is
// unset (single-machine dev).
const s3Public = new S3Client({
endpoint: process.env.S3_PUBLIC_URL ?? process.env.S3_ENDPOINT,
region: process.env.S3_REGION || "garage",
credentials,
forcePathStyle: true,
});
const DEFAULT_BUCKET = process.env.S3_BUCKET || "philproperties";
@@ -116,12 +130,13 @@ async function deleteFile(key) {
// ─── getSignedDownloadUrl ─────────────────────────────────────────────────────
//
// Generates a short-lived pre-signed GET URL.
// Useful if you ever need gated access to private assets (is_public = false).
// Generates a short-lived pre-signed GET URL using the public endpoint so the
// URL is resolvable from any machine (browser or proxy server), not just the
// one running Garage locally.
//
async function getSignedDownloadUrl(key, expiresInSeconds = 3600) {
return getSignedUrl(
s3,
s3Public,
new GetObjectCommand({ Bucket: DEFAULT_BUCKET, Key: key }),
{ expiresIn: expiresInSeconds }
);