e87390adb9
* update eslint and dependencies, fix linting errors that can be fixed with --fix * fix lots of linting errors * update eslintrc, fix some linting errors * fix all server side linting errors, untested * fix errors that fixing linting errors had caused * fix client side eslint errors * fix client side linting errors * fix refs lint errors * fix more linting errors * update eslint and dependencies, fix linting errors that can be fixed with --fix * fix lots of linting errors * update eslintrc, fix some linting errors * fix all server side linting errors, untested * fix errors that fixing linting errors had caused * fix client side eslint errors * fix client side linting errors * fix refs lint errors * fix more linting errors * fix some accessibility linting errors * fix a lot of linting errors * fix a billion more linting errors * hopefully fix all linting errors, still need to test * fix bugs that fixing linting had caused
30 lines
746 B
JavaScript
30 lines
746 B
JavaScript
import uuid from 'node-uuid';
|
|
import policy from 's3-policy';
|
|
|
|
function getExtension(filename) {
|
|
const i = filename.lastIndexOf('.');
|
|
return (i < 0) ? '' : filename.substr(i);
|
|
}
|
|
|
|
export function signS3(req, res) {
|
|
const fileExtension = getExtension(req.body.name);
|
|
const filename = uuid.v4() + fileExtension;
|
|
const acl = 'public-read';
|
|
const p = policy({
|
|
acl,
|
|
secret: process.env.AWS_SECRET_KEY,
|
|
length: 5000000, // in bytes?
|
|
bucket: process.env.S3_BUCKET,
|
|
key: filename,
|
|
expires: new Date(Date.now() + 60000),
|
|
});
|
|
const result = {
|
|
AWSAccessKeyId: process.env.AWS_ACCESS_KEY,
|
|
key: filename,
|
|
policy: p.policy,
|
|
signature: p.signature
|
|
};
|
|
return res.json(result);
|
|
}
|
|
|
|
export default signS3;
|