mirror of
https://github.com/skidoodle/albert.lol.git
synced 2025-02-15 06:09:15 +01:00
commit
This commit is contained in:
commit
b9dc57578a
26 changed files with 2590 additions and 0 deletions
26
pages/api/s3.tsx
Normal file
26
pages/api/s3.tsx
Normal 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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue