-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
79 lines (75 loc) · 1.75 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
73
74
75
76
77
78
79
const Vimeo = require("./utils/upload.js");
module.exports = {
init(config) {
var client = new Vimeo(
config.clientId,
config.clientSecret,
config.accessToken
);
return {
upload(file) {
return new Promise((resolve, reject) => {
client
.uploadFromBinary({
video: file.buffer,
name: file.hash,
description: file.alternativeText,
folderId: config.folderId,
})
.then((res) => {
if (config.premium) {
client
.getFromId(res.data.uri)
.then((res) => {
for (i = 0; i < res.data.files.length; i++) {
if (
res.data.files[i].rendition == "360p" ||
res.data.files[i].rendition == "540p" ||
res.data.files[i].rendition == "720p" ||
res.data.files[i].rendition == "1080p"
) {
file.url = res.data.files[i].link;
break;
}
}
if (file.url == undefined) {
file.url = res.data.link;
}
file.provider_metadata = {
link: res.data.link,
files: res.data.files,
};
resolve();
})
.catch((err) => {
console.log("get", err);
reject();
});
} else {
file.url = res.data.link;
resolve();
}
})
.catch((err) => {
console.log(err);
reject();
});
});
},
delete(file) {
str = file.provider_metadata.link;
client.vimeoClient.request(
{
method: "DELETE",
path: "/videos/" + str.split("/")[str.split("/").length - 1],
},
function (error, body, status_code, headers) {
if (error) {
console.log(error);
}
}
);
},
};
},
};