mirror of
https://github.com/filecoffee/filehost.git
synced 2024-11-13 19:49:56 +01:00
s3 gather statistics
This commit is contained in:
parent
bffa3a1814
commit
f1a636d018
1 changed files with 26 additions and 1 deletions
|
@ -57,8 +57,33 @@ const initializeS3Storage = (multerOptions, fileNameLength, s3Config) => {
|
|||
res.end();
|
||||
});
|
||||
};
|
||||
const gatherStatistics = async () => {
|
||||
let totalUploads = 0;
|
||||
let totalSize = 0;
|
||||
|
||||
return { writeFile, findFile };
|
||||
const listParams = {
|
||||
Bucket: s3Config.bucketName,
|
||||
};
|
||||
|
||||
const listObjects = async (params) => {
|
||||
const data = await s3.listObjectsV2(params).promise();
|
||||
data.Contents.forEach((item) => {
|
||||
totalUploads++;
|
||||
totalSize += item.Size;
|
||||
});
|
||||
|
||||
if (data.IsTruncated) {
|
||||
params.ContinuationToken = data.NextContinuationToken;
|
||||
await listObjects(params);
|
||||
}
|
||||
};
|
||||
|
||||
await listObjects(listParams);
|
||||
|
||||
return { totalUploads, totalSize };
|
||||
};
|
||||
|
||||
return { writeFile, findFile, gatherStatistics };
|
||||
};
|
||||
|
||||
module.exports = initializeS3Storage;
|
||||
|
|
Loading…
Reference in a new issue