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);
|
await pipelineAsync(objectStream, destStream);
|
||||||
console.log(`minio File downloaded to ${minioResources}/${objectName} \n ${destFile}`);
|
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(
|
export async function minioProxy(
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
res: ServerResponse,
|
res: ServerResponse,
|
||||||
@ -33,15 +43,17 @@ export async function minioProxy(
|
|||||||
if (stat.size === 0) {
|
if (stat.size === 0) {
|
||||||
return createNotFoundPage('Invalid proxy url');
|
return createNotFoundPage('Invalid proxy url');
|
||||||
}
|
}
|
||||||
|
const filterMetaData = filterKeys(stat.metaData, ['size', 'etag', 'last-modified']);
|
||||||
const contentLength = stat.size;
|
const contentLength = stat.size;
|
||||||
const etag = stat.etag;
|
const etag = stat.etag;
|
||||||
const lastModified = stat.lastModified.toISOString();
|
const lastModified = stat.lastModified.toISOString();
|
||||||
// console.log('contentType', stat.metaData);
|
const fileName = objectName.split('/').pop();
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Length': contentLength,
|
'Content-Length': contentLength,
|
||||||
etag,
|
etag,
|
||||||
'last-modified': lastModified,
|
'last-modified': lastModified,
|
||||||
...stat.metaData,
|
'file-name': fileName,
|
||||||
|
...filterMetaData,
|
||||||
});
|
});
|
||||||
const objectStream = await minioClient.getObject(bucketName, objectName);
|
const objectStream = await minioClient.getObject(bucketName, objectName);
|
||||||
objectStream.pipe(res, { end: true });
|
objectStream.pipe(res, { end: true });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user