node-ainzfb-new 1.6.2210-test → 1.6.2431-test
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -2
- package/src/changeAvt.js +85 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.2431-test",
|
4
4
|
"description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
|
5
5
|
"scripts": {
|
6
6
|
"test": "mocha",
|
@@ -36,7 +36,6 @@
|
|
36
36
|
"is-hexcolor": "^1.0.0",
|
37
37
|
"lodash": "",
|
38
38
|
"mqtt": "^4.3.7",
|
39
|
-
"node-superfetch": "^0.2.3",
|
40
39
|
"npmlog": "^1.2.0",
|
41
40
|
"path": "latest",
|
42
41
|
"pretty-ms": "latest",
|
package/src/changeAvt.js
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
/**
|
6
|
+
* It posts an image to a Facebook profile
|
7
|
+
* @param Api - The API object
|
8
|
+
* @param BotID - The ID of the bot you want to post the image to.
|
9
|
+
* @param form - The form data that you want to send.
|
10
|
+
* @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
|
11
|
+
* {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
|
12
|
+
*/
|
13
|
+
async function postImage(Api,BotID,form) {
|
14
|
+
var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
|
15
|
+
return JSON.parse(Data.split("for (;;);")[1]);
|
16
|
+
}
|
17
|
+
|
18
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
19
|
+
/* Changing the profile picture of the bot. */
|
20
|
+
return function changeAvt(link, caption, callback) {
|
21
|
+
var resolveFunc = function() {};
|
22
|
+
var rejectFunc = function() {};
|
23
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
24
|
+
resolveFunc = resolve;
|
25
|
+
rejectFunc = reject;
|
26
|
+
});
|
27
|
+
|
28
|
+
if (!callback) {
|
29
|
+
callback = function(err, data) {
|
30
|
+
if (err) return rejectFunc(err);
|
31
|
+
resolveFunc(data);
|
32
|
+
};
|
33
|
+
}
|
34
|
+
try {
|
35
|
+
var Fetch = require('axios')
|
36
|
+
Fetch.get(link, { responseType: "stream" }).then(data => {
|
37
|
+
postImage(api, ctx.userID, { file: data.data }).then(data => {
|
38
|
+
if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
|
39
|
+
var form = {
|
40
|
+
av: ctx.userID,
|
41
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
42
|
+
fb_api_caller_class: "RelayModern",
|
43
|
+
doc_id: "5066134240065849",
|
44
|
+
variables: JSON.stringify({
|
45
|
+
input: {
|
46
|
+
caption: (caption || ""),
|
47
|
+
existing_photo_id: data.payload.fbid,
|
48
|
+
expiration_time: null,
|
49
|
+
profile_id: ctx.userID,
|
50
|
+
profile_pic_method: "EXISTING",
|
51
|
+
profile_pic_source: "TIMELINE",
|
52
|
+
scaled_crop_rect: {
|
53
|
+
height: 1,
|
54
|
+
width: 1,
|
55
|
+
x: 0,
|
56
|
+
y: 0
|
57
|
+
},
|
58
|
+
skip_cropping: true,
|
59
|
+
actor_id: ctx.userID,
|
60
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
61
|
+
},
|
62
|
+
isPage: false,
|
63
|
+
isProfile: true,
|
64
|
+
scale: 3,
|
65
|
+
})
|
66
|
+
};
|
67
|
+
defaultFuncs
|
68
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
69
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
70
|
+
.then(function(resData) {
|
71
|
+
if (resData.error) throw resData;
|
72
|
+
else return callback(null,true)
|
73
|
+
})
|
74
|
+
.catch(function(err) {
|
75
|
+
return callback(err);
|
76
|
+
});
|
77
|
+
})
|
78
|
+
})
|
79
|
+
}
|
80
|
+
catch (e) {
|
81
|
+
throw e;
|
82
|
+
}
|
83
|
+
return returnPromise;
|
84
|
+
};
|
85
|
+
};
|