Created
October 5, 2016 07:15
-
-
Save FuYaoDe/fb733ed595137190f73e82a09952851c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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