-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
45 lines (37 loc) · 1.1 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
'use strict';
const fs = require('fs');
const FormData = require('form-data');
const action = async context => {
const endpoint = 'https://upload.giphy.com/v1/gifs';
const filePath = await context.filePath();
context.setProgress('Uploading…');
const form = new FormData();
form.append('api_key', context.config.get('apiKey'));
form.append('file', fs.createReadStream(filePath));
const response = await context.request(endpoint, {
method: 'post',
body: form
});
const {id} = JSON.parse(response.body).data;
context.copyToClipboard(`https://giphy.com/gifs/${id}`);
context.notify('URL to the GIF has been copied to the clipboard');
};
const config = {
apiKey: {
title: 'API key',
type: 'string',
minLength: 13,
default: '24j0dMD6Ml01YtYnEd3D3YvhsSgBmQw9', // Rate limited test key
required: true
}
};
const giphy = {
title: 'Share to GIPHY',
configDescription: 'The default API key is rate limited. In order to be able to upload more GIFs, create your own key here: https://developers.giphy.com/dashboard/',
formats: [
'gif'
],
action,
config
};
exports.shareServices = [giphy];