alicezetion 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"nonce":
|
1
|
+
{"nonce":4541222632038562979,"last_updated":{"seconds":1696933204,"nanos":504530000}}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
const log = require("npmlog");
|
5
|
+
const bluebird = require("bluebird");
|
6
|
+
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
8
|
+
function handleUpload(image, callback) {
|
9
|
+
const uploads = [];
|
10
|
+
|
11
|
+
const form = {
|
12
|
+
profile_id: ctx.i_userID || ctx.userID,
|
13
|
+
photo_source: 57,
|
14
|
+
av: ctx.i_userID || ctx.userID,
|
15
|
+
file: image
|
16
|
+
};
|
17
|
+
|
18
|
+
uploads.push(
|
19
|
+
defaultFuncs
|
20
|
+
.postFormData(
|
21
|
+
"https://www.facebook.com/profile/picture/upload/",
|
22
|
+
ctx.jar,
|
23
|
+
form,
|
24
|
+
{}
|
25
|
+
)
|
26
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
27
|
+
.then(function (resData) {
|
28
|
+
if (resData.error) {
|
29
|
+
throw resData;
|
30
|
+
}
|
31
|
+
return resData;
|
32
|
+
})
|
33
|
+
);
|
34
|
+
|
35
|
+
// resolve all promises
|
36
|
+
bluebird
|
37
|
+
.all(uploads)
|
38
|
+
.then(function (resData) {
|
39
|
+
callback(null, resData);
|
40
|
+
})
|
41
|
+
.catch(function (err) {
|
42
|
+
log.error("handleUpload", err);
|
43
|
+
return callback(err);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
return function changeAvatar(image, caption = "", timestamp = null, callback) {
|
48
|
+
let resolveFunc = function () { };
|
49
|
+
let rejectFunc = function () { };
|
50
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
51
|
+
resolveFunc = resolve;
|
52
|
+
rejectFunc = reject;
|
53
|
+
});
|
54
|
+
|
55
|
+
if (!timestamp && utils.getType(caption) === "Number") {
|
56
|
+
timestamp = caption;
|
57
|
+
caption = "";
|
58
|
+
}
|
59
|
+
|
60
|
+
if (!timestamp && !callback && (utils.getType(caption) == "Function" || utils.getType(caption) == "AsyncFunction")) {
|
61
|
+
callback = caption;
|
62
|
+
caption = "";
|
63
|
+
timestamp = null;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (!callback) callback = function (err, data) {
|
67
|
+
if (err) {
|
68
|
+
return rejectFunc(err);
|
69
|
+
}
|
70
|
+
resolveFunc(data);
|
71
|
+
};
|
72
|
+
|
73
|
+
if (!utils.isReadableStream(image))
|
74
|
+
return callback("Image is not a readable stream");
|
75
|
+
|
76
|
+
handleUpload(image, function (err, payload) {
|
77
|
+
if (err) {
|
78
|
+
return callback(err);
|
79
|
+
}
|
80
|
+
|
81
|
+
const form = {
|
82
|
+
av: ctx.i_userID || ctx.userID,
|
83
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
84
|
+
fb_api_caller_class: "RelayModern",
|
85
|
+
doc_id: "5066134240065849",
|
86
|
+
variables: JSON.stringify({
|
87
|
+
input: {
|
88
|
+
caption,
|
89
|
+
existing_photo_id: payload[0].payload.fbid,
|
90
|
+
expiration_time: timestamp,
|
91
|
+
profile_id: ctx.i_userID || ctx.userID,
|
92
|
+
profile_pic_method: "EXISTING",
|
93
|
+
profile_pic_source: "TIMELINE",
|
94
|
+
scaled_crop_rect: {
|
95
|
+
height: 1,
|
96
|
+
width: 1,
|
97
|
+
x: 0,
|
98
|
+
y: 0
|
99
|
+
},
|
100
|
+
skip_cropping: true,
|
101
|
+
actor_id: ctx.i_userID || ctx.userID,
|
102
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
103
|
+
},
|
104
|
+
isPage: false,
|
105
|
+
isProfile: true,
|
106
|
+
scale: 3
|
107
|
+
})
|
108
|
+
};
|
109
|
+
|
110
|
+
defaultFuncs
|
111
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
112
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
113
|
+
.then(function (resData) {
|
114
|
+
if (resData.errors) {
|
115
|
+
throw resData;
|
116
|
+
}
|
117
|
+
return callback(null, resData[0].data.profile_picture_set);
|
118
|
+
})
|
119
|
+
.catch(function (err) {
|
120
|
+
log.error("changeAvatar", err);
|
121
|
+
return callback(err);
|
122
|
+
});
|
123
|
+
});
|
124
|
+
|
125
|
+
return returnPromise;
|
126
|
+
};
|
127
|
+
};
|
package/package.json
CHANGED