Delete s3.js
This commit is contained in:
parent
2066ca4d8e
commit
9a47e93ad6
30
s3.js
30
s3.js
@ -1,30 +0,0 @@
|
|||||||
// s3.js
|
|
||||||
require('dotenv').config();
|
|
||||||
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
|
||||||
const { stringify } = require('csv-stringify/sync');
|
|
||||||
|
|
||||||
const s3 = new S3Client({
|
|
||||||
region: process.env.AWS_REGION
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uploads a CSV to s3://<bucket>/trends/<key>.csv with public-read ACL.
|
|
||||||
* @param {string} key Date key like '20250423'
|
|
||||||
* @param {Array<Object>} rows Array of DB rows to stringify into CSV
|
|
||||||
* @returns {string} Public URL of the uploaded CSV
|
|
||||||
*/
|
|
||||||
async function uploadTrendsCsv(key, rows) {
|
|
||||||
// Convert rows to CSV string (includes header)
|
|
||||||
const csv = stringify(rows, { header: true });
|
|
||||||
const cmd = new PutObjectCommand({
|
|
||||||
Bucket: process.env.S3_BUCKET_NAME,
|
|
||||||
Key: `trends/${key}.csv`,
|
|
||||||
Body: csv,
|
|
||||||
ContentType: 'text/csv',
|
|
||||||
ACL: 'public-read'
|
|
||||||
});
|
|
||||||
await s3.send(cmd);
|
|
||||||
return `${process.env.S3_BASE_URL}/${key}.csv`;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { uploadTrendsCsv };
|
|
Loading…
x
Reference in New Issue
Block a user