import * as Minio from "minio";
import { ObjectExpiration, bucketName } from "./consts";

export const minioClient = new Minio.Client({
  endPoint: process.env.MINIO_ENDPOINT!,
  port: parseInt(process.env.MINIO_PORT!),
  useSSL: process.env.SSL === "1",
  accessKey: process.env.MINIO_ACCESS_KEY!,
  secretKey: process.env.MINIO_SECRET_KEY!,
});

export const getPresignedUrl = async (path: string) => {
  const signedUrl = await minioClient.presignedGetObject(
    bucketName,
    path,
    ObjectExpiration
  );
  return signedUrl;
};
