mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the s3 save dump feature.
This commit is contained in:
@@ -23,16 +23,23 @@ async function getS3Client() {
|
||||
secretKey: settings.s3SecretAccessKey ?? "",
|
||||
};
|
||||
|
||||
const s3Client =
|
||||
env.NODE_ENV === "production"
|
||||
? new Minio.Client({
|
||||
...baseConfig,
|
||||
})
|
||||
: new Minio.Client({
|
||||
...baseConfig,
|
||||
port: Number(env.S3_PORT ?? 0),
|
||||
useSSL: env.S3_USE_SSL === "true",
|
||||
});
|
||||
// const s3Client =
|
||||
// env.NODE_ENV === "production"
|
||||
// ? new Minio.Client({
|
||||
// ...baseConfig,
|
||||
// useSSL: env.S3_USE_SSL === "true",
|
||||
// })
|
||||
// : new Minio.Client({
|
||||
// ...baseConfig,
|
||||
// port: Number(env.S3_PORT ?? 0),
|
||||
// useSSL: env.S3_USE_SSL === "true",
|
||||
// });
|
||||
|
||||
const s3Client = new Minio.Client({
|
||||
...baseConfig,
|
||||
port: Number(env.S3_PORT ?? 0),
|
||||
useSSL: env.S3_USE_SSL === "true",
|
||||
})
|
||||
|
||||
return s3Client;
|
||||
}
|
||||
@@ -168,3 +175,30 @@ export async function createPublicBucket({bucketName}: { bucketName: string }) {
|
||||
console.error("Error creating bucket:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a presigned URL for downloading a file from a private S3 bucket
|
||||
* @param bucketName name of the bucket
|
||||
* @param fileName name of the file
|
||||
* @param expiry expiry time in seconds (default 1 hour)
|
||||
* @returns presigned download URL
|
||||
*/
|
||||
export async function createPresignedUrlToDownload({
|
||||
bucketName,
|
||||
fileName,
|
||||
expiry = 60 * 60, // 1 hour
|
||||
}: {
|
||||
bucketName: string;
|
||||
fileName: string;
|
||||
expiry?: number;
|
||||
}) {
|
||||
const s3Client = await getS3Client();
|
||||
|
||||
// Optionally: ensure file exists
|
||||
const fileExists = await checkFileExistsInBucket({ bucketName, fileName });
|
||||
if (!fileExists) {
|
||||
throw new Error("File does not exist in the bucket.");
|
||||
}
|
||||
|
||||
return await s3Client.presignedGetObject(bucketName, fileName, expiry);
|
||||
}
|
||||
Reference in New Issue
Block a user