-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
67 lines (57 loc) · 1.31 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
"use strict";
const cloudinary = require("cloudinary");
const action = async (context) => {
const filePath = await context.filePath();
context.setProgress("Uploading…");
cloudinary.config({
cloud_name: context.config.get("cloud_name"),
api_key: context.config.get("api_key"),
api_secret: context.config.get("api_secret"),
});
let resourceType;
switch (filePath) {
case filePath.includes("gif"):
resourceType = "image";
break;
case filePath.includes("apng"):
resourceType = "image";
break;
case filePath.includes("webm"):
resourceType = "video";
break;
case filePath.includes("mp4"):
resourceType = "video";
break;
default:
resourceType = "video";
}
const upload = cloudinary.uploader.upload(`${filePath}`, {
resource_type: resourceType,
});
const response = await upload;
context.copyToClipboard(response.secure_url);
context.notify("Cloudinary URL copied to the clipboard");
};
const cloudin = {
title: "Share to Cloudinary",
formats: ["gif", "mp4", "webm", "apng"],
action,
config: {
cloud_name: {
title: "Cloud Name",
type: "string",
required: true,
},
api_key: {
title: "API Key",
type: "string",
required: true,
},
api_secret: {
title: "API Secret",
type: "string",
required: true,
},
},
};
exports.shareServices = [cloudin];