This commit is contained in:
skidoodle 2022-05-01 22:50:31 +02:00
commit b9dc57578a
26 changed files with 2590 additions and 0 deletions

26
pages/api/s3.tsx Normal file
View file

@ -0,0 +1,26 @@
import aws from 'aws-sdk';
export default async function handler(req, res) {
aws.config.update({
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.SECRET_KEY,
region: process.env.REGION,
endpoint: process.env.ENDPOINT,
signatureVersion: 'v4'
});
const s3 = new aws.S3();
const params = {
Bucket: 'i.albrt.hu'
}
const data = await s3.listObjectsV2(params).promise()
let totalsize = data.Contents!.reduce((acc, curr) => {
return acc + curr.Size! / 1024 / 1024 / 1024
}, 0)
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({
'objectCount': data.KeyCount,
'totalSize': (Math.round(totalsize * 100) / 100)
}, null, 2))
}