added update image route
This commit is contained in:
40
src/minio.ts
Normal file
40
src/minio.ts
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user