-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (66 loc) · 1.57 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
var axios = require("axios");
var fs = require("fs");
module.exports = class Agora {
constructor() {}
async login(username,password) {
this.username = username;
this.password = password;
var token = await axios({
url: 'https://apiprod.agoraimages.com/users.v2/auth/login',
method: 'POST',
data: {
"email": this.username,
"password": this.password
}
});
this.token = token.data.accessToken;
this.rft = token.data.refreshToken;
this.uid = token.data.userId;
return this.token;
}
async getProfile() {
var profile = await axios({
url: 'https://apiprod.agoraimages.com/users.v2/user/profile',
headers: {
authorization: 'Bearer ' + this.token
}
});
return profile.data;
}
async addToken(token) {
this.token = token;
var uid = await this.getProfile();
this.uid = uid.userId;
}
async upload(path,title) {
var up_url = await axios({
url: 'https://apiprod.agoraimages.com/media.v1/medias/upload',
method: 'POST',
data: {
"authorId": this.uid,
"locationDescription":"",
"metaData": {
"device":"Xiaomi Redmi Note 7 Pro",
"height":4000,
"width":3000
},
"platform":"ANDROID",
"title": title || "Image",
"userTags":""
},
headers: {
authorization: 'Bearer ' + this.token
}
});
var file = fs.createReadStream(path);
var result = await axios({
url: up_url.data.signedUrl,
method: 'PUT',
data: file,
headers: {
'Content-Type': 'image/*'
}
});
return result.data;
}
}