-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
42 lines (34 loc) · 961 Bytes
/
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
'use strict';
const fs = require('fs');
const url = require('url');
const FormData = require('form-data');
const action = async context => {
const endpoint = 'https://api.imgur.com/3/image';
const filePath = await context.filePath();
const form = new FormData();
context.setProgress('Uploading…');
form.append('image', fs.createReadStream(filePath));
const response = await context.request(endpoint, {
method: 'post',
body: form,
headers: {authorization: `Client-ID ${context.config.get('clientId')}`}
});
const link = url.parse(JSON.parse(response.body).data.link);
link.protocol = 'https';
context.copyToClipboard(url.format(link));
context.notify('URL to the GIF has been copied to the clipboard');
};
const imgur = {
title: 'Share to Imgur',
formats: ['gif'],
action,
config: {
clientId: {
title: 'Client ID',
type: 'string',
default: '34b90e75ab1c04b',
required: true
}
}
};
exports.shareServices = [imgur];