mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
fix: local regression
replace my hard coded thinking Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
+26
-11
@@ -18,16 +18,30 @@ const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
|
|||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
const path = require("path");
|
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({
|
const s3 = new S3Client({
|
||||||
endpoint: process.env.S3_ENDPOINT,
|
endpoint: process.env.S3_ENDPOINT,
|
||||||
region: process.env.S3_REGION || "garage",
|
region: process.env.S3_REGION || "garage",
|
||||||
credentials: {
|
credentials,
|
||||||
accessKeyId: process.env.S3_ACCESS_KEY,
|
forcePathStyle: true,
|
||||||
secretAccessKey: process.env.S3_SECRET_KEY,
|
});
|
||||||
},
|
|
||||||
forcePathStyle: true, // required — Garage does not support DNS-style bucket addressing
|
// 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";
|
const DEFAULT_BUCKET = process.env.S3_BUCKET || "philproperties";
|
||||||
@@ -116,12 +130,13 @@ async function deleteFile(key) {
|
|||||||
|
|
||||||
// ─── getSignedDownloadUrl ─────────────────────────────────────────────────────
|
// ─── getSignedDownloadUrl ─────────────────────────────────────────────────────
|
||||||
//
|
//
|
||||||
// Generates a short-lived pre-signed GET URL.
|
// Generates a short-lived pre-signed GET URL using the public endpoint so the
|
||||||
// Useful if you ever need gated access to private assets (is_public = false).
|
// URL is resolvable from any machine (browser or proxy server), not just the
|
||||||
|
// one running Garage locally.
|
||||||
//
|
//
|
||||||
async function getSignedDownloadUrl(key, expiresInSeconds = 3600) {
|
async function getSignedDownloadUrl(key, expiresInSeconds = 3600) {
|
||||||
return getSignedUrl(
|
return getSignedUrl(
|
||||||
s3,
|
s3Public,
|
||||||
new GetObjectCommand({ Bucket: DEFAULT_BUCKET, Key: key }),
|
new GetObjectCommand({ Bucket: DEFAULT_BUCKET, Key: key }),
|
||||||
{ expiresIn: expiresInSeconds }
|
{ expiresIn: expiresInSeconds }
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user