@dongdev/fca-unofficial 1.0.11 → 1.0.13
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 +6 -0
- package/index.js +71 -105
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
@@ -40,7 +40,7 @@ async function checkForUpdates() {
|
|
40
40
|
logger("Auto update is disabled", "info");
|
41
41
|
}
|
42
42
|
try {
|
43
|
-
const response = await axios.get("https://raw.githubusercontent.com/DongDev-VN/fca-unofficial/
|
43
|
+
const response = await axios.get("https://raw.githubusercontent.com/DongDev-VN/fca-unofficial/main/package.json");
|
44
44
|
const remoteVersion = response.data.version;
|
45
45
|
const localPackage = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
|
46
46
|
const localVersion = localPackage.version;
|
@@ -62,7 +62,7 @@ if (global.fca.config.autoUpdate) {
|
|
62
62
|
}
|
63
63
|
const Boolean_Option = [
|
64
64
|
"online",
|
65
|
-
"selfListen",
|
65
|
+
"selfListen",
|
66
66
|
"listenEvents",
|
67
67
|
"updatePresence",
|
68
68
|
"forceLogin",
|
@@ -73,7 +73,7 @@ const Boolean_Option = [
|
|
73
73
|
"emitReady",
|
74
74
|
];
|
75
75
|
function setOptions(globalOptions, options) {
|
76
|
-
Object.keys(options).map(function(key) {
|
76
|
+
Object.keys(options).map(function (key) {
|
77
77
|
switch (Boolean_Option.includes(key)) {
|
78
78
|
case true: {
|
79
79
|
globalOptions[key] = Boolean(options[key]);
|
@@ -133,6 +133,7 @@ function buildAPI(globalOptions, html, jar) {
|
|
133
133
|
const cookies = jar.getCookies("https://www.facebook.com");
|
134
134
|
const userCookie = cookies.find(c => c.cookieString().startsWith("c_user="));
|
135
135
|
const tiktikCookie = cookies.find(c => c.cookieString().startsWith("i_user="));
|
136
|
+
console.log(cookies)
|
136
137
|
if (userCookie.length === 0 && tiktikCookie.length === 0) {
|
137
138
|
return log.error('login', "Không tìm thấy cookie cho người dùng, vui lòng kiểm tra lại thông tin đăng nhập")
|
138
139
|
} else if (!userCookie && !tiktikCookie) {
|
@@ -145,7 +146,7 @@ function buildAPI(globalOptions, html, jar) {
|
|
145
146
|
logger(`Logged in as ${userID}`, 'info');
|
146
147
|
try {
|
147
148
|
clearInterval(checkVerified);
|
148
|
-
} catch (_) {}
|
149
|
+
} catch (_) { }
|
149
150
|
const clientID = ((Math.random() * 2147483648) | 0).toString(16);
|
150
151
|
let mqttEndpoint, region, fb_dtsg, irisSeqID;
|
151
152
|
try {
|
@@ -208,7 +209,7 @@ function buildAPI(globalOptions, html, jar) {
|
|
208
209
|
require("fs")
|
209
210
|
.readdirSync(__dirname + "/src/")
|
210
211
|
.filter((v) => v.endsWith(".js"))
|
211
|
-
.map(function(v) {
|
212
|
+
.map(function (v) {
|
212
213
|
api[v.replace(".js", "")] = require("./src/" + v)(defaultFuncs, api, ctx);
|
213
214
|
});
|
214
215
|
api.listen = api.listenMqtt;
|
@@ -223,130 +224,95 @@ function buildAPI(globalOptions, html, jar) {
|
|
223
224
|
console.error("An error occurred while refreshing fb_dtsg", err);
|
224
225
|
});
|
225
226
|
}, 1000 * 60 * 60 * 24);
|
226
|
-
return
|
227
|
+
return {
|
228
|
+
ctx,
|
229
|
+
defaultFuncs,
|
230
|
+
api
|
231
|
+
};
|
227
232
|
}
|
228
|
-
|
229
|
-
|
230
|
-
email,
|
231
|
-
password,
|
232
|
-
globalOptions,
|
233
|
-
callback,
|
234
|
-
prCallback
|
235
|
-
) {
|
233
|
+
|
234
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
236
235
|
let mainPromise = null;
|
237
236
|
const jar = utils.getJar();
|
238
237
|
if (appState) {
|
239
|
-
|
240
|
-
appState =
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
})
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
path: "/",
|
254
|
-
expires: new Date().getTime() + 1000 * 60 * 60 * 24 * 365,
|
255
|
-
});
|
238
|
+
try {
|
239
|
+
appState = JSON.parse(appState);
|
240
|
+
} catch (e) {
|
241
|
+
try {
|
242
|
+
appState = appState;
|
243
|
+
} catch (e) {
|
244
|
+
return callback(new Error("Failed to parse appState"));
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
try {
|
249
|
+
appState.forEach(c => {
|
250
|
+
const str = `${c.key}=${c.value}; expires=${c.expires}; domain=${c.domain}; path=${c.path};`;
|
251
|
+
jar.setCookie(str, "http://" + c.domain);
|
256
252
|
});
|
257
|
-
|
253
|
+
|
254
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
|
255
|
+
.then(utils.saveCookies(jar));
|
256
|
+
} catch (e) {
|
257
|
+
process.exit(0);
|
258
258
|
}
|
259
|
-
appState.map(function(c) {
|
260
|
-
const str =
|
261
|
-
c.key +
|
262
|
-
"=" +
|
263
|
-
c.value +
|
264
|
-
"; expires=" +
|
265
|
-
c.expires +
|
266
|
-
"; domain=" +
|
267
|
-
c.domain +
|
268
|
-
"; path=" +
|
269
|
-
c.path +
|
270
|
-
";";
|
271
|
-
jar.setCookie(str, "http://" + c.domain);
|
272
|
-
});
|
273
|
-
mainPromise = utils
|
274
|
-
.get("https://www.facebook.com/", jar, null, globalOptions, {
|
275
|
-
noRef: true,
|
276
|
-
})
|
277
|
-
.then(utils.saveCookies(jar));
|
278
259
|
} else {
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
260
|
+
mainPromise = utils
|
261
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
262
|
+
.then(utils.saveCookies(jar))
|
263
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
264
|
+
.then(() => utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar)));
|
265
|
+
}
|
266
|
+
|
267
|
+
function handleRedirect(res) {
|
268
|
+
const reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
269
|
+
const redirect = reg.exec(res.body);
|
270
|
+
if (redirect && redirect[1]) {
|
271
|
+
return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
286
272
|
}
|
273
|
+
return res;
|
287
274
|
}
|
288
|
-
|
289
|
-
let
|
290
|
-
let api = null;
|
275
|
+
|
276
|
+
let ctx, api;
|
291
277
|
mainPromise = mainPromise
|
292
|
-
.then(
|
293
|
-
|
294
|
-
const
|
295
|
-
if (
|
296
|
-
|
297
|
-
|
298
|
-
.then(utils.saveCookies(jar));
|
278
|
+
.then(handleRedirect)
|
279
|
+
.then(res => {
|
280
|
+
const mobileAgentRegex = /MPageLoadClientMetrics/gs;
|
281
|
+
if (!mobileAgentRegex.test(res.body)) {
|
282
|
+
globalOptions.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36";
|
283
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
299
284
|
}
|
300
285
|
return res;
|
301
286
|
})
|
302
|
-
.then(
|
287
|
+
.then(handleRedirect)
|
288
|
+
.then(res => {
|
303
289
|
const html = res.body;
|
304
|
-
const
|
305
|
-
ctx =
|
306
|
-
|
307
|
-
api = stuff[2];
|
290
|
+
const Obj = buildAPI(globalOptions, html, jar);
|
291
|
+
ctx = Obj.ctx;
|
292
|
+
api = Obj.api;
|
308
293
|
return res;
|
309
294
|
});
|
295
|
+
|
310
296
|
if (globalOptions.pageID) {
|
311
297
|
mainPromise = mainPromise
|
312
|
-
.then(
|
313
|
-
|
314
|
-
|
315
|
-
ctx.globalOptions.pageID +
|
316
|
-
"/messages/?section=messages&subsection=inbox",
|
317
|
-
ctx.jar,
|
318
|
-
null,
|
319
|
-
globalOptions
|
320
|
-
);
|
321
|
-
})
|
322
|
-
.then(function(resData) {
|
323
|
-
let url = utils
|
324
|
-
.getFrom(
|
325
|
-
resData.body,
|
326
|
-
'window.location.replace("https:\\/\\/www.facebook.com\\',
|
327
|
-
'");'
|
328
|
-
)
|
329
|
-
.split("\\")
|
330
|
-
.join("");
|
298
|
+
.then(() => utils.get(`https://www.facebook.com/${globalOptions.pageID}/messages/?section=messages&subsection=inbox`, jar, null, globalOptions))
|
299
|
+
.then(resData => {
|
300
|
+
let url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
331
301
|
url = url.substring(0, url.length - 1);
|
332
|
-
return utils.get(
|
333
|
-
"https://www.facebook.com" + url,
|
334
|
-
ctx.jar,
|
335
|
-
null,
|
336
|
-
globalOptions
|
337
|
-
);
|
302
|
+
return utils.get('https://www.facebook.com' + url, jar, null, globalOptions);
|
338
303
|
});
|
339
304
|
}
|
305
|
+
|
340
306
|
mainPromise
|
341
|
-
.then(
|
342
|
-
|
343
|
-
|
307
|
+
.then(async () => {
|
308
|
+
log.info('Đăng nhập thành công');
|
309
|
+
callback(null, api);
|
344
310
|
})
|
345
|
-
.catch(
|
346
|
-
log.error("login", e.error || e);
|
311
|
+
.catch(e => {
|
347
312
|
callback(e);
|
348
313
|
});
|
349
314
|
}
|
315
|
+
|
350
316
|
function login(loginData, options, callback) {
|
351
317
|
if (
|
352
318
|
utils.getType(options) === "Function" ||
|
@@ -379,11 +345,11 @@ function login(loginData, options, callback) {
|
|
379
345
|
) {
|
380
346
|
let rejectFunc = null;
|
381
347
|
let resolveFunc = null;
|
382
|
-
var returnPromise = new Promise(function(resolve, reject) {
|
348
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
383
349
|
resolveFunc = resolve;
|
384
350
|
rejectFunc = reject;
|
385
351
|
});
|
386
|
-
prCallback = function(error, api) {
|
352
|
+
prCallback = function (error, api) {
|
387
353
|
if (error) {
|
388
354
|
return rejectFunc(error);
|
389
355
|
}
|