node-ainzfb-new 1.6.2511-test → 1.6.2729-test
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/getUserID.js +2 -2
- package/utils.js +67 -111
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.2729-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",
|
@@ -35,12 +35,12 @@
|
|
35
35
|
"https-proxy-agent": "latest",
|
36
36
|
"is-hexcolor": "^1.0.0",
|
37
37
|
"lodash": "",
|
38
|
-
"mqtt": "^3.
|
38
|
+
"mqtt": "^4.3.7",
|
39
39
|
"node-superfetch": "^0.2.3",
|
40
40
|
"npmlog": "^1.2.0",
|
41
41
|
"path": "latest",
|
42
42
|
"pretty-ms": "latest",
|
43
|
-
"request": "^2.
|
43
|
+
"request": "^2.88.2",
|
44
44
|
"semver": "latest",
|
45
45
|
"sus-support": "git+https://github.com/amogusdevlol/sus-support.git",
|
46
46
|
"websocket-stream": "latest"
|
package/src/getUserID.js
CHANGED
@@ -41,10 +41,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
41
41
|
path: "/home.php",
|
42
42
|
request_id: utils.getGUID()
|
43
43
|
};
|
44
|
-
|
44
|
+
var { getAccessToken } = require('../Extra/ExtraAddons');
|
45
45
|
defaultFuncs
|
46
46
|
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
47
|
-
.then(
|
47
|
+
.then(getAccessToken(ctx, defaultFuncs))
|
48
48
|
.then(function (resData) {
|
49
49
|
if (resData.error) throw resData;
|
50
50
|
|
package/utils.js
CHANGED
@@ -1019,119 +1019,75 @@ function makeDefaults(html, userID, ctx) {
|
|
1019
1019
|
}
|
1020
1020
|
|
1021
1021
|
function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
|
1022
|
-
if (retryCount == undefined)
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
data.request.headers["Content-Type"].split(";")[0] ===
|
1046
|
-
"multipart/form-data"
|
1047
|
-
) {
|
1048
|
-
return bluebird
|
1049
|
-
.delay(retryTime)
|
1050
|
-
.then(function () {
|
1051
|
-
return defaultFuncs.postFormData(
|
1052
|
-
url,
|
1053
|
-
ctx.jar,
|
1054
|
-
data.request.formData,
|
1055
|
-
{}
|
1056
|
-
);
|
1057
|
-
})
|
1058
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
|
1059
|
-
} else {
|
1060
|
-
return bluebird
|
1061
|
-
.delay(retryTime)
|
1062
|
-
.then(function () {
|
1063
|
-
return defaultFuncs.post(url, ctx.jar, data.request.formData);
|
1064
|
-
})
|
1065
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
|
1066
|
-
}
|
1067
|
-
}
|
1068
|
-
if (data.statusCode !== 200)
|
1069
|
-
throw new Error(
|
1070
|
-
"parseAndCheckLogin got status code: " +
|
1071
|
-
data.statusCode +
|
1072
|
-
". Bailing out of trying to parse response."
|
1073
|
-
);
|
1074
|
-
|
1075
|
-
var res = null;
|
1076
|
-
try {
|
1077
|
-
res = JSON.parse(makeParsable(data.body));
|
1078
|
-
} catch (e) {
|
1079
|
-
throw {
|
1080
|
-
error: "JSON.parse error. Check the `detail` property on this error.",
|
1081
|
-
detail: e,
|
1082
|
-
res: data.body
|
1083
|
-
};
|
1084
|
-
}
|
1085
|
-
|
1086
|
-
// In some cases the response contains only a redirect URL which should be followed
|
1087
|
-
if (res.redirect && data.request.method === "GET") {
|
1088
|
-
return defaultFuncs
|
1089
|
-
.get(res.redirect, ctx.jar)
|
1090
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs));
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
// TODO: handle multiple cookies?
|
1094
|
-
if (
|
1095
|
-
res.jsmods &&
|
1096
|
-
res.jsmods.require &&
|
1097
|
-
Array.isArray(res.jsmods.require[0]) &&
|
1098
|
-
res.jsmods.require[0][0] === "Cookie"
|
1099
|
-
) {
|
1100
|
-
res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
|
1101
|
-
"_js_",
|
1102
|
-
""
|
1103
|
-
);
|
1104
|
-
var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
|
1105
|
-
var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
|
1106
|
-
ctx.jar.setCookie(cookie, "https://www.facebook.com");
|
1107
|
-
ctx.jar.setCookie(cookie2, "https://www.messenger.com");
|
1108
|
-
}
|
1109
|
-
|
1110
|
-
// On every request we check if we got a DTSG and we mutate the context so that we use the latest
|
1111
|
-
// one for the next requests.
|
1112
|
-
if (res.jsmods && Array.isArray(res.jsmods.require)) {
|
1113
|
-
var arr = res.jsmods.require;
|
1114
|
-
for (var i in arr) {
|
1115
|
-
if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
|
1116
|
-
ctx.fb_dtsg = arr[i][3][0];
|
1117
|
-
|
1118
|
-
// Update ttstamp since that depends on fb_dtsg
|
1119
|
-
ctx.ttstamp = "2";
|
1120
|
-
for (var j = 0; j < ctx.fb_dtsg.length; j++) {
|
1121
|
-
ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
|
1122
|
-
}
|
1022
|
+
if (retryCount == undefined) retryCount = 0;
|
1023
|
+
return function(data) {
|
1024
|
+
return bluebird.try(function() {
|
1025
|
+
log.verbose("parseAndCheckLogin", data.body);
|
1026
|
+
if (data.statusCode >= 500 && data.statusCode < 600) {
|
1027
|
+
if (retryCount >= 5) {
|
1028
|
+
throw {
|
1029
|
+
error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
|
1030
|
+
statusCode: data.statusCode,
|
1031
|
+
res: data.body
|
1032
|
+
};
|
1033
|
+
}
|
1034
|
+
retryCount++;
|
1035
|
+
var retryTime = Math.floor(Math.random() * 5000);
|
1036
|
+
log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
|
1037
|
+
var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
|
1038
|
+
if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
|
1039
|
+
return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
|
1040
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
|
1041
|
+
} else {
|
1042
|
+
return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
|
1043
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
|
1044
|
+
}
|
1123
1045
|
}
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1046
|
+
if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
|
1047
|
+
|
1048
|
+
var res = null;
|
1049
|
+
try {
|
1050
|
+
res = JSON.parse(makeParsable(data.body));
|
1051
|
+
} catch (e) {
|
1052
|
+
throw {
|
1053
|
+
error: "JSON.parse error. Check the `detail` property on this error.",
|
1054
|
+
detail: e,
|
1055
|
+
res: data.body
|
1056
|
+
};
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
// In some cases the response contains only a redirect URL which should be followed
|
1060
|
+
if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
|
1061
|
+
|
1062
|
+
// TODO: handle multiple cookies?
|
1063
|
+
if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
|
1064
|
+
res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
|
1065
|
+
var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
|
1066
|
+
var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
|
1067
|
+
ctx.jar.setCookie(cookie, "https://www.facebook.com");
|
1068
|
+
ctx.jar.setCookie(cookie2, "https://www.messenger.com");
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
// On every request we check if we got a DTSG and we mutate the context so that we use the latest
|
1072
|
+
// one for the next requests.
|
1073
|
+
if (res.jsmods && Array.isArray(res.jsmods.require)) {
|
1074
|
+
var arr = res.jsmods.require;
|
1075
|
+
for (var i in arr) {
|
1076
|
+
if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
|
1077
|
+
ctx.fb_dtsg = arr[i][3][0];
|
1078
|
+
|
1079
|
+
// Update ttstamp since that depends on fb_dtsg
|
1080
|
+
ctx.ttstamp = "2";
|
1081
|
+
for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
|
1082
|
+
}
|
1083
|
+
}
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
if (res.error === 1357001) throw { error: "Not logged in." };
|
1087
|
+
return res;
|
1088
|
+
});
|
1132
1089
|
};
|
1133
|
-
|
1134
|
-
|
1090
|
+
}
|
1135
1091
|
|
1136
1092
|
function saveCookies(jar) {
|
1137
1093
|
return function(res) {
|