This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
72 lines (65 loc) · 1.68 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const {createHash} = require('crypto');
const through2 = require('through2');
const {readFile} = require('fs-extra');
const action = async context => {
const uploadEndpoint = 'https://api.zeit.co/v2/now/files';
const deploymentEndpoint = 'https://api.zeit.co/v2/now/deployments';
const Authorization = 'Bearer ' + context.config.get('token');
const filePath = await context.filePath();
const data = await readFile(filePath);
const sha = createHash('sha1').update(data).digest('hex');
const stream = through2();
stream.write(data);
stream.end();
context.setProgress('Uploading…');
await context.request(uploadEndpoint, {
headers: {
'Content-Type': 'application/octet-stream',
'x-now-digest': sha,
'x-now-size': data.length,
Authorization
},
body: stream
});
context.setProgress('Creating Now deployment…');
const deploymentResponse = await context.request(deploymentEndpoint, {
headers: {
Authorization
},
json: true,
body: {
name: context.config.get('name'),
deploymentType: 'STATIC',
files: [
{
file: context.defaultFileName,
sha,
size: data.length
}
]
}
});
context.copyToClipboard(`https://${deploymentResponse.body.url}`);
context.notify(`URL to the ${context.prettyFormat} has been copied to the clipboard`);
};
const now = {
title: 'Share on Now',
formats: ['gif', 'mp4', 'webm', 'apng'],
action,
config: {
token: {
title: 'Now token',
description: 'Create one here https://zeit.co/account/tokens',
type: 'string',
required: true
},
name: {
title: 'Name used in the deployment URL',
type: 'string',
default: 'kapture',
required: true
}
}
};
exports.shareServices = [now];