All checks were successful
backend-action / build-image (push) Successful in 1m9s
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import * as minio from "minio";
|
|
import { Config } from "./config";
|
|
|
|
export function createClient() {
|
|
const mc = new minio.Client({
|
|
endPoint: Config.minioEndpoint,
|
|
useSSL: Config.minioSSL,
|
|
port: Config.minioPort,
|
|
accessKey: Config.minioAccessKey,
|
|
secretKey: Config.minioSecretKey,
|
|
});
|
|
|
|
return mc;
|
|
}
|
|
|
|
export async function createUploadImageUrl(
|
|
mc: minio.Client,
|
|
objectName: string,
|
|
contentType: string,
|
|
) {
|
|
const policy = mc.newPostPolicy();
|
|
policy.setKey(objectName);
|
|
policy.setBucket(Config.bucketName);
|
|
const expires = new Date();
|
|
expires.setSeconds(30 * 60);
|
|
policy.setExpires(expires);
|
|
policy.setContentType(contentType);
|
|
policy.setContentDisposition(`attachment; filename="${objectName}"`);
|
|
policy.setContentLengthRange(1, 3 * 1024 * 1024);
|
|
const rs = await mc.presignedPostPolicy(policy);
|
|
return rs;
|
|
}
|
|
|
|
export async function createBucket(mc: minio.Client) {
|
|
if (!(await mc.bucketExists(Config.bucketName))) {
|
|
await mc.makeBucket(Config.bucketName);
|
|
} else {
|
|
console.log("Bucket already exists");
|
|
}
|
|
}
|