Skip to content

Instantly share code, notes, and snippets.

@FuYaoDe
Created October 5, 2016 07:15
Show Gist options
  • Save FuYaoDe/fb733ed595137190f73e82a09952851c to your computer and use it in GitHub Desktop.
Save FuYaoDe/fb733ed595137190f73e82a09952851c to your computer and use it in GitHub Desktop.
import sig from "amazon-s3-url-signer";
import fse from 'fs-extra';
import request from 'request';
import {exec} from 'child_process';
import path from 'path';
let home = process.cwd();
module.exports = {
getS3Url: (path,time) => {
try {
let bucket = sig.urlSigner(sails.config.S3.id, sails.config.S3.key, sails.config.S3.options);
let url = bucket.getUrl('GET', path, 'comic-zj4ul42k6', time);
return url;
} catch (e) {
sails.log.error(e);
throw e
}
},
putS3Url: (path, time) => {
try {
let bucket = sig.urlSigner(sails.config.S3.id, sails.config.S3.key, sails.config.S3.options);
let url = bucket.getUrl('PUT', path, 'comic-zj4ul42k6', time);
return url;
} catch (e) {
sails.log.error(e);
throw e;
}
},
putFile: async(src, url) => {
try {
let cmd = `curl --upload-file "${src}" "${url}"`;
await new Promise((done) => {
exec(cmd, function(error, stdout, stderr) {
if (error) {
sails.log.info(error);
throw error;
}
sails.log.info(stdout);
done();
});
});
return 'ok';
} catch (e) {
sails.log.error(e);
throw e;
}
}
// end
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment