32 lines
913 B
TypeScript
32 lines
913 B
TypeScript
import { Client } from "minio";
|
|
|
|
let _internalClient: Client | null = null;
|
|
let _publicClient: Client | null = null;
|
|
|
|
export function getMinioClient(): Client {
|
|
if (!_internalClient) {
|
|
_internalClient = new Client({
|
|
endPoint: process.env.MINIO_URL!,
|
|
port: Number(process.env.MINIO_PORT),
|
|
useSSL: false,
|
|
accessKey: process.env.MINIO_ACCESS_KEY!,
|
|
secretKey: process.env.MINIO_SECRET_KEY!,
|
|
});
|
|
}
|
|
return _internalClient;
|
|
}
|
|
|
|
export function getMinioPublicClient(): Client {
|
|
if (!_publicClient) {
|
|
const url = new URL(process.env.MINIO_PUBLIC_URL!);
|
|
|
|
_publicClient = new Client({
|
|
endPoint: url.hostname,
|
|
port: url.port ? Number(url.port) : (url.protocol === "https:" ? 443 : 80),
|
|
useSSL: url.protocol === "https:",
|
|
accessKey: process.env.MINIO_ACCESS_KEY!,
|
|
secretKey: process.env.MINIO_SECRET_KEY!,
|
|
});
|
|
}
|
|
return _publicClient;
|
|
} |