-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paths3.js
More file actions
38 lines (34 loc) · 813 Bytes
/
s3.js
File metadata and controls
38 lines (34 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const knox = require('knox');
const headers = Object.assign(
{
'x-amz-acl': 'public-read',
'x-amz-storage-class': 'REDUCED_REDUNDANCY',
},
require('./headers')
);
const client = knox.createClient({
key: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
bucket: process.env.AWS_BUCKET,
});
function put({ bin, rev }, html) {
const url = `/${bin}/${rev}`;
return new Promise((resolve, reject) => {
const req = client.put(url, {
'Content-Length': Buffer.byteLength(html),
...headers,
});
req.on('response', res => {
if (res.statusCode === 200) {
resolve(req.url);
}
// FIXME if not 200?
});
req.on('error', reject);
req.end(html);
});
}
module.exports = {
put,
};