2021-04-28 21:48:35 +00:00
|
|
|
const URL = require('url');
|
|
|
|
const do_wb = require('../../src/util');
|
|
|
|
fs = require('fs');
|
2021-04-30 00:23:13 +00:00
|
|
|
const AWS = require('aws-sdk');
|
2021-04-28 21:48:35 +00:00
|
|
|
|
|
|
|
module.exports = function (req, res) {
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
|
|
const url = URL.parse(req.url, true);
|
2021-05-03 16:06:05 +00:00
|
|
|
// const s3 = new AWS.S3({ endpoint: 'http://localhost:4566', s3ForcePathStyle: true });
|
|
|
|
const s3 = new AWS.S3();
|
2021-04-30 00:23:13 +00:00
|
|
|
|
|
|
|
const getFile = (filename) => {
|
2021-05-03 16:06:05 +00:00
|
|
|
s3.getObject({ Bucket: 'sheetaki-test', Key: filename }, function (err, data) {
|
2021-04-28 21:48:35 +00:00
|
|
|
if (err) return res.status(500).send(err.message || err);
|
2021-04-30 00:23:13 +00:00
|
|
|
do_wb(req, data.Body, url, res);
|
2021-04-28 21:48:35 +00:00
|
|
|
});
|
|
|
|
}
|
2021-04-30 00:23:13 +00:00
|
|
|
|
|
|
|
if (!url.query.filename) return res.status(400).send("Must specify filename");
|
|
|
|
if (url.query.filename){
|
|
|
|
getFile(url.query.filename);
|
|
|
|
// fs.readFile(url.query.filename, (err, body) => {
|
|
|
|
// if (err) return res.status(500).send(err.message || err);
|
|
|
|
// do_wb(req, body, url, res);
|
|
|
|
// });
|
|
|
|
}
|
2021-04-28 21:48:35 +00:00
|
|
|
};
|