feat: add minioProxy info
This commit is contained in:
parent
0ac2d6518c
commit
feaad567b4
@ -16,6 +16,16 @@ export async function downloadFileFromMinio(fileUrl: string, destFile: string) {
|
||||
await pipelineAsync(objectStream, destStream);
|
||||
console.log(`minio File downloaded to ${minioResources}/${objectName} \n ${destFile}`);
|
||||
}
|
||||
export const filterKeys = (metaData: Record<string, string>, clearKeys: string[] = []) => {
|
||||
const keys = Object.keys(metaData);
|
||||
// remove X-Amz- meta data
|
||||
const removeKeys = ['password', 'accesskey', 'secretkey', ...clearKeys];
|
||||
const filteredKeys = keys.filter((key) => !removeKeys.includes(key));
|
||||
return filteredKeys.reduce((acc, key) => {
|
||||
acc[key] = metaData[key];
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
};
|
||||
export async function minioProxy(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
@ -33,15 +43,17 @@ export async function minioProxy(
|
||||
if (stat.size === 0) {
|
||||
return createNotFoundPage('Invalid proxy url');
|
||||
}
|
||||
const filterMetaData = filterKeys(stat.metaData, ['size', 'etag', 'last-modified']);
|
||||
const contentLength = stat.size;
|
||||
const etag = stat.etag;
|
||||
const lastModified = stat.lastModified.toISOString();
|
||||
// console.log('contentType', stat.metaData);
|
||||
const fileName = objectName.split('/').pop();
|
||||
res.writeHead(200, {
|
||||
'Content-Length': contentLength,
|
||||
etag,
|
||||
'last-modified': lastModified,
|
||||
...stat.metaData,
|
||||
'file-name': fileName,
|
||||
...filterMetaData,
|
||||
});
|
||||
const objectStream = await minioClient.getObject(bucketName, objectName);
|
||||
objectStream.pipe(res, { end: true });
|
||||
|
Loading…
x
Reference in New Issue
Block a user