@dongdev/fca-unofficial 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/func/checkUpdate.js +9 -9
- package/func/logger.js +40 -104
- package/module/login.js +4 -4
- package/module/loginHelper.js +3 -3
- package/module/options.js +5 -9
- package/package.json +5 -5
- package/src/api/action/addExternalModule.js +5 -5
- package/src/api/action/changeAvatar.js +11 -10
- package/src/api/action/changeBio.js +7 -8
- package/src/api/action/getCurrentUserID.js +1 -1
- package/src/api/action/handleFriendRequest.js +5 -5
- package/src/api/action/logout.js +9 -8
- package/src/api/action/refreshFb_dtsg.js +17 -12
- package/src/api/action/setPostReaction.js +10 -11
- package/src/api/action/unfriend.js +3 -4
- package/src/api/http/httpGet.js +7 -8
- package/src/api/http/httpPost.js +7 -8
- package/src/api/http/postFormData.js +6 -5
- package/src/api/messaging/addUserToGroup.js +0 -1
- package/src/api/messaging/changeAdminStatus.js +108 -89
- package/src/api/messaging/changeArchivedStatus.js +6 -6
- package/src/api/messaging/changeBlockedStatus.js +3 -4
- package/src/api/messaging/changeGroupImage.js +72 -117
- package/src/api/messaging/changeNickname.js +59 -48
- package/src/api/messaging/changeThreadColor.js +61 -47
- package/src/api/messaging/changeThreadEmoji.js +106 -0
- package/src/api/messaging/createNewGroup.js +5 -5
- package/src/api/messaging/createPoll.js +36 -63
- package/src/api/messaging/deleteMessage.js +4 -4
- package/src/api/messaging/deleteThread.js +4 -4
- package/src/api/messaging/forwardAttachment.js +38 -47
- package/src/api/messaging/getFriendsList.js +5 -6
- package/src/api/messaging/getMessage.js +4 -9
- package/src/api/messaging/handleMessageRequest.js +5 -5
- package/src/api/messaging/markAsDelivered.js +5 -5
- package/src/api/messaging/markAsRead.js +7 -7
- package/src/api/messaging/markAsReadAll.js +3 -4
- package/src/api/messaging/markAsSeen.js +7 -7
- package/src/api/messaging/muteThread.js +3 -4
- package/src/api/messaging/removeUserFromGroup.js +82 -56
- package/src/api/messaging/resolvePhotoUrl.js +2 -3
- package/src/api/messaging/searchForThread.js +2 -3
- package/src/api/messaging/sendMessage.js +171 -101
- package/src/api/messaging/sendMessageMqtt.js +14 -12
- package/src/api/messaging/sendTypingIndicator.js +11 -11
- package/src/api/messaging/setMessageReaction.js +68 -82
- package/src/api/messaging/setTitle.js +77 -48
- package/src/api/messaging/shareContact.js +2 -4
- package/src/api/messaging/threadColors.js +0 -3
- package/src/api/messaging/unsendMessage.js +74 -37
- package/src/api/messaging/uploadAttachment.js +11 -9
- package/src/api/socket/core/connectMqtt.js +180 -0
- package/src/api/socket/core/getSeqID.js +25 -0
- package/src/api/socket/core/getTaskResponseData.js +22 -0
- package/src/api/socket/core/markDelivery.js +12 -0
- package/src/api/socket/core/parseDelta.js +351 -0
- package/src/api/socket/detail/buildStream.js +176 -68
- package/src/api/socket/detail/constants.js +24 -0
- package/src/api/socket/listenMqtt.js +80 -1005
- package/src/api/{messaging → threads}/getThreadHistory.js +5 -22
- package/src/api/threads/getThreadInfo.js +35 -248
- package/src/api/threads/getThreadList.js +20 -20
- package/src/api/threads/getThreadPictures.js +3 -4
- package/src/api/users/getUserID.js +5 -6
- package/src/api/users/getUserInfo.js +305 -73
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/database/models/user.js +32 -0
- package/src/database/userData.js +89 -0
- package/src/utils/constants.js +12 -2
- package/src/utils/format.js +1051 -0
- package/src/utils/request.js +75 -7
- package/src/api/threads/changeThreadEmoji.js +0 -55
- package/src/utils/index.js +0 -1497
package/CHANGELOG.md
CHANGED
package/func/checkUpdate.js
CHANGED
@@ -23,34 +23,34 @@ function getInstalledVersion() {
|
|
23
23
|
|
24
24
|
async function checkAndUpdateVersion(callback) {
|
25
25
|
try {
|
26
|
-
logger("
|
26
|
+
logger("Checking version...", "info");
|
27
27
|
const latest = (await execPromise(`npm view ${pkgName} version`)).stdout.trim();
|
28
28
|
const installed = getInstalledVersion();
|
29
29
|
if (!installed || installed !== latest) {
|
30
|
-
logger(
|
30
|
+
logger(`New version available (${latest}). Current version (${installed || "not installed"}). Updating...`, "info");
|
31
31
|
try {
|
32
32
|
const { stderr } = await execPromise(`npm i ${pkgName}@latest`);
|
33
33
|
if (stderr) logger(stderr, "error");
|
34
|
-
logger(
|
34
|
+
logger(`Updated fca to the latest version: ${latest}, Restart to apply`, "info");
|
35
35
|
callback(null);
|
36
36
|
} catch (e) {
|
37
|
-
logger(`
|
37
|
+
logger(`Error running npm install: ${e.error || e}. Trying to install from GitHub...`, "error");
|
38
38
|
try {
|
39
|
-
const { stderr } = await execPromise("npm i https://github.com/
|
39
|
+
const { stderr } = await execPromise("npm i https://github.com/Donix-VN/fca-unofficial");
|
40
40
|
if (stderr) logger(stderr, "error");
|
41
|
-
logger(
|
41
|
+
logger(`Installed from GitHub successfully: ${latest}`, "info");
|
42
42
|
callback(null);
|
43
43
|
} catch (gitErr) {
|
44
|
-
logger(`
|
44
|
+
logger(`Error installing from GitHub: ${gitErr.error || gitErr}`, "error");
|
45
45
|
callback(gitErr.error || gitErr);
|
46
46
|
}
|
47
47
|
}
|
48
48
|
} else {
|
49
|
-
logger(
|
49
|
+
logger(`You're already on the latest version - ${latest}`, "info");
|
50
50
|
callback(null);
|
51
51
|
}
|
52
52
|
} catch (err) {
|
53
|
-
logger(`
|
53
|
+
logger(`Error checking version: ${err}`, "error");
|
54
54
|
callback(err);
|
55
55
|
}
|
56
56
|
}
|
package/func/logger.js
CHANGED
@@ -1,112 +1,48 @@
|
|
1
1
|
const chalk = require("chalk");
|
2
2
|
const gradient = require("gradient-string");
|
3
|
+
|
3
4
|
const themes = [
|
4
|
-
"blue",
|
5
|
-
"dream2",
|
6
|
-
"dream",
|
7
|
-
"test",
|
8
|
-
"fiery",
|
9
|
-
"rainbow",
|
10
|
-
"pastel",
|
11
|
-
"cristal",
|
12
|
-
"red",
|
13
|
-
"aqua",
|
14
|
-
"pink",
|
15
|
-
"retro",
|
16
|
-
"sunlight",
|
17
|
-
"teen",
|
18
|
-
"summer",
|
19
|
-
"flower",
|
20
|
-
"ghost",
|
21
|
-
"hacker"
|
5
|
+
"blue", "dream2", "dream", "fiery", "rainbow", "pastel", "cristal", "red", "aqua", "pink", "retro", "sunlight", "teen", "summer", "flower", "ghost", "hacker"
|
22
6
|
];
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if (
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
{ color: "blue", pos: 1 }
|
45
|
-
]);
|
46
|
-
error = chalk.red.bold;
|
47
|
-
} else if (theme.toLowerCase() === "fiery") {
|
48
|
-
co = gradient("#fc2803", "#fc6f03", "#fcba03");
|
49
|
-
error = chalk.red.bold;
|
50
|
-
} else if (theme.toLowerCase() === "rainbow") {
|
51
|
-
co = gradient.rainbow;
|
52
|
-
error = chalk.red.bold;
|
53
|
-
} else if (theme.toLowerCase() === "pastel") {
|
54
|
-
co = gradient.pastel;
|
55
|
-
error = chalk.red.bold;
|
56
|
-
} else if (theme.toLowerCase() === "cristal") {
|
57
|
-
co = gradient.cristal;
|
58
|
-
error = chalk.red.bold;
|
59
|
-
} else if (theme.toLowerCase() === "red") {
|
60
|
-
co = gradient("red", "orange");
|
61
|
-
error = chalk.red.bold;
|
62
|
-
} else if (theme.toLowerCase() === "aqua") {
|
63
|
-
co = gradient("#0030ff", "#4e6cf2");
|
64
|
-
error = chalk.blueBright;
|
65
|
-
} else if (theme.toLowerCase() === "pink") {
|
66
|
-
cra = gradient("purple", "pink");
|
67
|
-
co = gradient("#d94fff", "purple");
|
68
|
-
} else if (theme.toLowerCase() === "retro") {
|
69
|
-
cra = gradient("#d94fff", "purple");
|
70
|
-
co = gradient.retro;
|
71
|
-
} else if (theme.toLowerCase() === "sunlight") {
|
72
|
-
cra = gradient("#f5bd31", "#f5e131");
|
73
|
-
co = gradient("orange", "#ffff00", "#ffe600");
|
74
|
-
} else if (theme.toLowerCase() === "teen") {
|
75
|
-
cra = gradient("#00a9c7", "#853858", "#853858", "#00a9c7");
|
76
|
-
co = gradient.teen;
|
77
|
-
} else if (theme.toLowerCase() === "summer") {
|
78
|
-
cra = gradient("#fcff4d", "#4de1ff");
|
79
|
-
co = gradient.summer;
|
80
|
-
} else if (theme.toLowerCase() === "flower") {
|
81
|
-
cra = gradient("blue", "purple", "yellow", "#81ff6e");
|
82
|
-
co = gradient.pastel;
|
83
|
-
} else if (theme.toLowerCase() === "ghost") {
|
84
|
-
cra = gradient("#0a658a", "#0a7f8a", "#0db5aa");
|
85
|
-
co = gradient.mind;
|
86
|
-
} else if (theme === "hacker") {
|
87
|
-
cra = chalk.hex("#4be813");
|
88
|
-
co = gradient("#47a127", "#0eed19", "#27f231");
|
89
|
-
} else {
|
90
|
-
co = gradient("#243aff", "#4687f0", "#5800d4");
|
91
|
-
error = chalk.red.bold;
|
7
|
+
|
8
|
+
function buildGradient(name) {
|
9
|
+
const t = String(name || "").toLowerCase();
|
10
|
+
if (t === "blue") return gradient([{ color: "#1affa3", pos: 0.2 }, { color: "cyan", pos: 0.4 }, { color: "pink", pos: 0.6 }, { color: "cyan", pos: 0.8 }, { color: "#1affa3", pos: 1 }]);
|
11
|
+
if (t === "dream2") return gradient("blue", "pink");
|
12
|
+
if (t === "dream") return gradient([{ color: "blue", pos: 0.2 }, { color: "pink", pos: 0.3 }, { color: "gold", pos: 0.6 }, { color: "pink", pos: 0.8 }, { color: "blue", pos: 1 }]);
|
13
|
+
if (t === "fiery") return gradient("#fc2803", "#fc6f03", "#fcba03");
|
14
|
+
if (t === "rainbow") return gradient.rainbow;
|
15
|
+
if (t === "pastel") return gradient.pastel;
|
16
|
+
if (t === "cristal") return gradient.cristal;
|
17
|
+
if (t === "red") return gradient("red", "orange");
|
18
|
+
if (t === "aqua") return gradient("#0030ff", "#4e6cf2");
|
19
|
+
if (t === "pink") return gradient("#d94fff", "purple");
|
20
|
+
if (t === "retro") return gradient.retro;
|
21
|
+
if (t === "sunlight") return gradient("orange", "#ffff00", "#ffe600");
|
22
|
+
if (t === "teen") return gradient.teen;
|
23
|
+
if (t === "summer") return gradient.summer;
|
24
|
+
if (t === "flower") return gradient("blue", "purple", "yellow", "#81ff6e");
|
25
|
+
if (t === "ghost") return gradient.mind;
|
26
|
+
if (t === "hacker") return gradient("#47a127", "#0eed19", "#27f231");
|
27
|
+
return gradient("#243aff", "#4687f0", "#5800d4");
|
92
28
|
}
|
29
|
+
|
30
|
+
const themeName = themes[Math.floor(Math.random() * themes.length)];
|
31
|
+
const co = buildGradient(themeName);
|
32
|
+
|
93
33
|
module.exports = (text, type) => {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
case "error":
|
99
|
-
process.stderr.write(
|
100
|
-
chalk.bold.hex("#ff0000").bold(`\r[ FCA-ERROR ]`) + ` > ${text}` + "\n"
|
101
|
-
);
|
102
|
-
break;
|
103
|
-
case "info":
|
104
|
-
process.stderr.write(chalk.bold(co(`\r[ FCA-UNO ] > ${text}`) + "\n"));
|
105
|
-
break;
|
106
|
-
default:
|
107
|
-
process.stderr.write(
|
108
|
-
chalk.bold(co(`\r${String(type).toUpperCase()} ${text}`) + "\n")
|
109
|
-
);
|
110
|
-
break;
|
34
|
+
const s = String(type || "info").toLowerCase();
|
35
|
+
if (s === "warn") {
|
36
|
+
process.stderr.write(co(`\r[ FCA-WARN ] > ${text}`) + "\n");
|
37
|
+
return;
|
111
38
|
}
|
39
|
+
if (s === "error") {
|
40
|
+
process.stderr.write(chalk.bold.hex("#ff0000")(`\r[ FCA-ERROR ]`) + ` > ${text}\n`);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
if (s === "info") {
|
44
|
+
process.stderr.write(chalk.bold(co(`\r[ FCA-UNO ] > ${text}`)) + "\n");
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
process.stderr.write(chalk.bold(co(`\r[ ${s.toUpperCase()} ] > ${text}`)) + "\n");
|
112
48
|
};
|
package/module/login.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const { getType } = require("../src/utils/format");
|
3
3
|
const { setOptions } = require("./options");
|
4
4
|
const { loadConfig } = require("./config");
|
5
5
|
const { config } = loadConfig();
|
@@ -8,7 +8,7 @@ global.fca = { config };
|
|
8
8
|
const loginHelper = require("./loginHelper");
|
9
9
|
|
10
10
|
function login(loginData, options, callback) {
|
11
|
-
if (
|
11
|
+
if (getType(options) === "Function" || getType(options) === "AsyncFunction") {
|
12
12
|
callback = options;
|
13
13
|
options = {};
|
14
14
|
}
|
@@ -28,7 +28,7 @@ function login(loginData, options, callback) {
|
|
28
28
|
};
|
29
29
|
setOptions(globalOptions, options);
|
30
30
|
let prCallback = null;
|
31
|
-
if (
|
31
|
+
if (getType(callback) !== "Function" && getType(callback) !== "AsyncFunction") {
|
32
32
|
let rejectFunc = null;
|
33
33
|
let resolveFunc = null;
|
34
34
|
var returnPromise = new Promise(function (resolve, reject) {
|
@@ -44,4 +44,4 @@ function login(loginData, options, callback) {
|
|
44
44
|
loginHelper(loginData.appState, loginData.Cookie,loginData.email, loginData.password, globalOptions, callback, prCallback);
|
45
45
|
return returnPromise;
|
46
46
|
}
|
47
|
-
module.exports = login;
|
47
|
+
module.exports = login;
|
package/module/loginHelper.js
CHANGED
@@ -547,7 +547,7 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback,
|
|
547
547
|
console.error("Database connection failed:", error && error.message ? error.message : String(error));
|
548
548
|
});
|
549
549
|
|
550
|
-
logger("FCA fix/update by DongDev", "info");
|
550
|
+
logger("FCA fix/update by DongDev (Donix-VN)", "info");
|
551
551
|
|
552
552
|
const ctx = {
|
553
553
|
userID,
|
@@ -606,7 +606,7 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback,
|
|
606
606
|
});
|
607
607
|
});
|
608
608
|
|
609
|
-
logger(`Loaded ${loaded} FCA API methods${skipped ? `, skipped ${skipped} duplicates` : ""}
|
609
|
+
logger(`Loaded ${loaded} FCA API methods${skipped ? `, skipped ${skipped} duplicates` : ""}`);
|
610
610
|
|
611
611
|
api.listen = api.listenMqtt;
|
612
612
|
|
@@ -632,4 +632,4 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback,
|
|
632
632
|
}
|
633
633
|
}
|
634
634
|
|
635
|
-
module.exports = loginHelper;
|
635
|
+
module.exports = loginHelper;
|
package/module/options.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
const
|
1
|
+
const { getType } = require("../src/utils/format");
|
2
|
+
const { setProxy } = require("../src/utils/request");
|
2
3
|
const logger = require("../func/logger");
|
3
4
|
const Boolean_Option = [
|
4
5
|
"online",
|
@@ -20,11 +21,6 @@ function setOptions(globalOptions, options) {
|
|
20
21
|
continue;
|
21
22
|
}
|
22
23
|
switch (key) {
|
23
|
-
case "pauseLog": {
|
24
|
-
if (options.pauseLog) log.pause();
|
25
|
-
else log.resume();
|
26
|
-
break;
|
27
|
-
}
|
28
24
|
case "userAgent": {
|
29
25
|
globalOptions.userAgent = options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
|
30
26
|
break;
|
@@ -32,10 +28,10 @@ function setOptions(globalOptions, options) {
|
|
32
28
|
case "proxy": {
|
33
29
|
if (typeof options.proxy !== "string") {
|
34
30
|
delete globalOptions.proxy;
|
35
|
-
|
31
|
+
setProxy();
|
36
32
|
} else {
|
37
33
|
globalOptions.proxy = options.proxy;
|
38
|
-
|
34
|
+
setProxy(globalOptions.proxy);
|
39
35
|
}
|
40
36
|
break;
|
41
37
|
}
|
@@ -46,4 +42,4 @@ function setOptions(globalOptions, options) {
|
|
46
42
|
}
|
47
43
|
}
|
48
44
|
}
|
49
|
-
module.exports = { setOptions, Boolean_Option };
|
45
|
+
module.exports = { setOptions, Boolean_Option };
|
package/package.json
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dongdev/fca-unofficial",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.8",
|
4
4
|
"description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
|
5
5
|
"main": "index.js",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
8
8
|
"url": "git+https://github.com/Donix-VN/fca-unofficial.git"
|
9
9
|
},
|
10
|
-
"author": "Avery, David, Maude, Benjamin, UIRI, DongDev, LunarKrystal",
|
10
|
+
"author": "Avery, David, Maude, Benjamin, UIRI, DongDev (Donix-VN), LunarKrystal",
|
11
11
|
"license": "MIT",
|
12
12
|
"dependencies": {
|
13
|
-
"axios": "
|
13
|
+
"axios": "latest",
|
14
14
|
"axios-cookiejar-support": "^5.0.5",
|
15
15
|
"bluebird": "^3.7.2",
|
16
16
|
"chalk": "^4.1.2",
|
@@ -47,9 +47,9 @@
|
|
47
47
|
"node": ">=10.x"
|
48
48
|
},
|
49
49
|
"types": "index.d.ts",
|
50
|
-
"homepage": "https://github.com/
|
50
|
+
"homepage": "https://github.com/Donix-VN/fca-unofficial#readme",
|
51
51
|
"bugs": {
|
52
|
-
"url": "https://github.com/
|
52
|
+
"url": "https://github.com/Donix-VN/fca-unofficial/issues"
|
53
53
|
},
|
54
54
|
"directories": {
|
55
55
|
"test": "test"
|
@@ -1,16 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const
|
3
|
+
const { getType } = require("../../utils/format");
|
4
4
|
|
5
5
|
module.exports = function(defaultFuncs, api, ctx) {
|
6
6
|
return function addExternalModule(moduleObj) {
|
7
|
-
if (
|
7
|
+
if (getType(moduleObj) == "Object") {
|
8
8
|
for (const apiName in moduleObj) {
|
9
|
-
if (
|
9
|
+
if (getType(moduleObj[apiName]) == "Function") {
|
10
10
|
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
11
11
|
} else {
|
12
12
|
throw new Error(
|
13
|
-
`Item "${apiName}" in moduleObj must be a function, not ${
|
13
|
+
`Item "${apiName}" in moduleObj must be a function, not ${getType(
|
14
14
|
moduleObj[apiName]
|
15
15
|
)}!`
|
16
16
|
);
|
@@ -18,7 +18,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
18
18
|
}
|
19
19
|
} else {
|
20
20
|
throw new Error(
|
21
|
-
`moduleObj must be an object, not ${
|
21
|
+
`moduleObj must be an object, not ${getType(moduleObj)}!`
|
22
22
|
);
|
23
23
|
}
|
24
24
|
};
|
@@ -1,16 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { isReadableStream } = require("../../utils/constants");
|
5
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
6
|
+
const { formatID, getType } = require("../../utils/format");
|
6
7
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
8
|
function handleUpload(image, callback) {
|
8
9
|
const uploads = [];
|
9
10
|
|
10
11
|
const form = {
|
11
|
-
profile_id: ctx.
|
12
|
+
profile_id: ctx.userID,
|
12
13
|
photo_source: 57,
|
13
|
-
av: ctx.
|
14
|
+
av: ctx.userID,
|
14
15
|
file: image
|
15
16
|
};
|
16
17
|
|
@@ -22,7 +23,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
22
23
|
form,
|
23
24
|
{}
|
24
25
|
)
|
25
|
-
.then(
|
26
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
26
27
|
.then(function(resData) {
|
27
28
|
if (resData.error) {
|
28
29
|
throw resData;
|
@@ -55,7 +56,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
55
56
|
rejectFunc = reject;
|
56
57
|
});
|
57
58
|
|
58
|
-
if (!timestamp &&
|
59
|
+
if (!timestamp && getType(caption) === "Number") {
|
59
60
|
timestamp = caption;
|
60
61
|
caption = "";
|
61
62
|
}
|
@@ -63,8 +64,8 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
63
64
|
if (
|
64
65
|
!timestamp &&
|
65
66
|
!callback &&
|
66
|
-
(
|
67
|
-
|
67
|
+
(getType(caption) == "Function" ||
|
68
|
+
getType(caption) == "AsyncFunction")
|
68
69
|
) {
|
69
70
|
callback = caption;
|
70
71
|
caption = "";
|
@@ -79,7 +80,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
79
80
|
resolveFunc(data);
|
80
81
|
};
|
81
82
|
|
82
|
-
if (!
|
83
|
+
if (!isReadableStream(image))
|
83
84
|
return callback("Image is not a readable stream");
|
84
85
|
|
85
86
|
handleUpload(image, function(err, payload) {
|
@@ -118,7 +119,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
118
119
|
|
119
120
|
defaultFuncs
|
120
121
|
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
121
|
-
.then(
|
122
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
122
123
|
.then(function(resData) {
|
123
124
|
if (resData.errors) {
|
124
125
|
throw resData;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
5
|
+
const { getType } = require("../../utils/format");
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeBio(bio, publish, callback) {
|
8
8
|
let resolveFunc = function() {};
|
@@ -14,8 +14,8 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
14
14
|
|
15
15
|
if (!callback) {
|
16
16
|
if (
|
17
|
-
|
18
|
-
|
17
|
+
getType(publish) == "Function" ||
|
18
|
+
getType(publish) == "AsyncFunction"
|
19
19
|
) {
|
20
20
|
callback = publish;
|
21
21
|
} else {
|
@@ -28,11 +28,11 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
31
|
-
if (
|
31
|
+
if (getType(publish) != "Boolean") {
|
32
32
|
publish = false;
|
33
33
|
}
|
34
34
|
|
35
|
-
if (
|
35
|
+
if (getType(bio) != "String") {
|
36
36
|
bio = "";
|
37
37
|
publish = false;
|
38
38
|
}
|
@@ -40,7 +40,6 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
40
40
|
const form = {
|
41
41
|
fb_api_caller_class: "RelayModern",
|
42
42
|
fb_api_req_friendly_name: "ProfileCometSetBioMutation",
|
43
|
-
// This doc_is is valid as of May 23, 2020
|
44
43
|
doc_id: "2725043627607610",
|
45
44
|
variables: JSON.stringify({
|
46
45
|
input: {
|
@@ -58,7 +57,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
58
57
|
|
59
58
|
defaultFuncs
|
60
59
|
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
61
|
-
.then(
|
60
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
62
61
|
.then(function(resData) {
|
63
62
|
if (resData.errors) {
|
64
63
|
throw resData;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
5
|
+
const { getType } = require("../../utils/format");
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function handleFriendRequest(userID, accept, callback) {
|
8
|
-
if (
|
8
|
+
if (getType(accept) !== "Boolean") {
|
9
9
|
throw {
|
10
10
|
error: "Please pass a boolean as a second argument."
|
11
11
|
};
|
@@ -28,7 +28,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
const form = {
|
31
|
-
viewer_id: ctx.
|
31
|
+
viewer_id: ctx.userID,
|
32
32
|
"frefs[0]": "jwl",
|
33
33
|
floc: "friend_center_requests",
|
34
34
|
ref: "/reqs.php",
|
@@ -37,7 +37,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
37
37
|
|
38
38
|
defaultFuncs
|
39
39
|
.post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
|
40
|
-
.then(
|
40
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
41
41
|
.then(function(resData) {
|
42
42
|
if (resData.payload.err) {
|
43
43
|
throw {
|
package/src/api/action/logout.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
5
|
+
const { getFrom } = require("../../utils/constants");
|
6
|
+
const { saveCookies } = require("../../utils/client");
|
6
7
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
8
|
return function logout(callback) {
|
8
9
|
let resolveFunc = function() {};
|
@@ -31,7 +32,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
31
32
|
ctx.jar,
|
32
33
|
form
|
33
34
|
)
|
34
|
-
.then(
|
35
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
35
36
|
.then(function(resData) {
|
36
37
|
const elem = resData.jsmods.instances[0][2][0].filter(function(v) {
|
37
38
|
return v.value === "logout";
|
@@ -42,14 +43,14 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
42
43
|
})[0][1].__html;
|
43
44
|
|
44
45
|
const form = {
|
45
|
-
fb_dtsg:
|
46
|
-
ref:
|
47
|
-
h:
|
46
|
+
fb_dtsg: getFrom(html, '"fb_dtsg" value="', '"'),
|
47
|
+
ref: getFrom(html, '"ref" value="', '"'),
|
48
|
+
h: getFrom(html, '"h" value="', '"')
|
48
49
|
};
|
49
50
|
|
50
51
|
return defaultFuncs
|
51
52
|
.post("https://www.facebook.com/logout.php", ctx.jar, form)
|
52
|
-
.then(
|
53
|
+
.then(saveCookies(ctx.jar));
|
53
54
|
})
|
54
55
|
.then(function(res) {
|
55
56
|
if (!res.headers) {
|
@@ -58,7 +59,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
58
59
|
|
59
60
|
return defaultFuncs
|
60
61
|
.get(res.headers.location, ctx.jar)
|
61
|
-
.then(
|
62
|
+
.then(saveCookies(ctx.jar));
|
62
63
|
})
|
63
64
|
.then(function() {
|
64
65
|
ctx.loggedIn = false;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { getFrom } = require("../../utils/constants");
|
5
|
+
const { get } = require("../../utils/request")
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function refreshFb_dtsg(obj, callback) {
|
8
8
|
let resolveFunc, rejectFunc;
|
@@ -11,15 +11,15 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
11
11
|
rejectFunc = reject;
|
12
12
|
});
|
13
13
|
if (
|
14
|
-
|
15
|
-
|
14
|
+
getType(obj) === "Function" ||
|
15
|
+
getType(obj) === "AsyncFunction"
|
16
16
|
) {
|
17
17
|
callback = obj;
|
18
18
|
obj = {};
|
19
19
|
}
|
20
20
|
if (!obj) obj = {};
|
21
|
-
if (
|
22
|
-
throw
|
21
|
+
if (getType(obj) !== "Object") {
|
22
|
+
throw Error(
|
23
23
|
"The first parameter must be an object or a callback function"
|
24
24
|
);
|
25
25
|
}
|
@@ -27,19 +27,24 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
27
27
|
callback = (err, data) => (err ? rejectFunc(err) : resolveFunc(data));
|
28
28
|
}
|
29
29
|
if (Object.keys(obj).length === 0) {
|
30
|
-
|
31
|
-
|
30
|
+
get(
|
31
|
+
"https://www.facebook.com/",
|
32
|
+
ctx.jar,
|
33
|
+
null,
|
34
|
+
ctx.globalOptions,
|
35
|
+
{
|
32
36
|
noRef: true
|
33
|
-
}
|
37
|
+
}
|
38
|
+
)
|
34
39
|
.then(resData => {
|
35
|
-
const fb_dtsg =
|
40
|
+
const fb_dtsg = getFrom(
|
36
41
|
resData.body,
|
37
42
|
'["DTSGInitData",[],{"token":"',
|
38
43
|
'","'
|
39
44
|
);
|
40
|
-
const jazoest =
|
45
|
+
const jazoest = getFrom(resData.body, "jazoest=", '",');
|
41
46
|
if (!fb_dtsg) {
|
42
|
-
throw
|
47
|
+
throw Error(
|
43
48
|
"Could not find fb_dtsg in HTML after requesting Facebook."
|
44
49
|
);
|
45
50
|
}
|