added update image route

This commit is contained in:
2024-04-20 14:52:43 +07:00
parent ed8c0e77f2
commit ee9963c3b6
11 changed files with 914 additions and 35 deletions

40
src/minio.ts Normal file
View File

@@ -0,0 +1,40 @@
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
) {
let policy = mc.newPostPolicy();
policy.setKey(objectName);
policy.setBucket(Config.bucketName);
let expires = new Date();
expires.setSeconds(30 * 60);
policy.setExpires(expires);
policy.setContentType(contentType);
policy.setContentDisposition(`attachment; filename="${objectName}"`);
policy.setContentLengthRange(1, 3 * 1024 * 1024);
let 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");
}
}