@dongdev/fca-unofficial 2.0.4 → 2.0.6
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 +38 -31
- package/func/checkUpdate.js +58 -0
- package/index.js +1 -1
- package/module/config.js +14 -9
- package/module/login.js +4 -2
- package/module/loginHelper.js +8 -7
- package/module/options.js +1 -1
- package/package.json +57 -57
- package/.gitattributes +0 -1
- package/html.html +0 -474
package/CHANGELOG.md
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# Changelog
|
2
|
-
Too lazy to write changelog, sorry! (will write changelog in the next release, through.)
|
3
|
-
## v1.0.10 - 2025-04-24
|
4
|
-
- Hotfix / auto bump
|
5
|
-
|
6
|
-
## v1.0.11 - 2025-04-24
|
7
|
-
- Hotfix / auto bump
|
8
|
-
|
9
|
-
## v1.0.12 - 2025-04-28
|
10
|
-
- Hotfix / auto bump
|
11
|
-
|
12
|
-
## v1.0.13 - 2025-04-28
|
13
|
-
- Hotfix / auto bump
|
14
|
-
|
15
|
-
## v1.0.14 - 2025-04-28
|
16
|
-
- Hotfix / auto bump
|
17
|
-
|
18
|
-
## v1.0.15 - 2025-05-03
|
19
|
-
- Hotfix / auto bump
|
20
|
-
|
21
|
-
## v1.0.16 - 2025-05-07
|
22
|
-
- Hotfix / auto bump
|
23
|
-
|
24
|
-
## v1.0.17 - 2025-05-07
|
25
|
-
- Hotfix / auto bump
|
26
|
-
|
27
|
-
## v1.0.18 - 2025-05-22
|
28
|
-
- Hotfix / auto bump
|
29
|
-
|
30
|
-
## v1.0.19 - 2025-05-23
|
31
|
-
- Hotfix / auto bump
|
1
|
+
# Changelog
|
2
|
+
Too lazy to write changelog, sorry! (will write changelog in the next release, through.)
|
3
|
+
## v1.0.10 - 2025-04-24
|
4
|
+
- Hotfix / auto bump
|
5
|
+
|
6
|
+
## v1.0.11 - 2025-04-24
|
7
|
+
- Hotfix / auto bump
|
8
|
+
|
9
|
+
## v1.0.12 - 2025-04-28
|
10
|
+
- Hotfix / auto bump
|
11
|
+
|
12
|
+
## v1.0.13 - 2025-04-28
|
13
|
+
- Hotfix / auto bump
|
14
|
+
|
15
|
+
## v1.0.14 - 2025-04-28
|
16
|
+
- Hotfix / auto bump
|
17
|
+
|
18
|
+
## v1.0.15 - 2025-05-03
|
19
|
+
- Hotfix / auto bump
|
20
|
+
|
21
|
+
## v1.0.16 - 2025-05-07
|
22
|
+
- Hotfix / auto bump
|
23
|
+
|
24
|
+
## v1.0.17 - 2025-05-07
|
25
|
+
- Hotfix / auto bump
|
26
|
+
|
27
|
+
## v1.0.18 - 2025-05-22
|
28
|
+
- Hotfix / auto bump
|
29
|
+
|
30
|
+
## v1.0.19 - 2025-05-23
|
31
|
+
- Hotfix / auto bump
|
32
32
|
|
33
33
|
## v2.0.0 - 2025-10-05
|
34
34
|
- Hotfix / auto bump
|
@@ -41,3 +41,10 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
|
|
41
41
|
|
42
42
|
## v2.0.3 - 2025-10-05
|
43
43
|
- Hotfix / auto bump
|
44
|
+
|
45
|
+
## v2.0.4 - 2025-10-05
|
46
|
+
- Hotfix / auto bump
|
47
|
+
|
48
|
+
## v2.0.5 - 2025-10-06
|
49
|
+
- Now you can turn on/off autoLogin in config file.
|
50
|
+
- Added autoUpdate feature.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
const logger = require("./logger");
|
2
|
+
const fs = require("fs");
|
3
|
+
const { exec } = require("child_process");
|
4
|
+
const pkgName = "@dongdev/fca-unofficial";
|
5
|
+
|
6
|
+
function execPromise(cmd) {
|
7
|
+
return new Promise((resolve, reject) => {
|
8
|
+
exec(cmd, (error, stdout, stderr) => {
|
9
|
+
if (error) return reject({ error, stderr });
|
10
|
+
resolve({ stdout, stderr });
|
11
|
+
});
|
12
|
+
});
|
13
|
+
}
|
14
|
+
|
15
|
+
function getInstalledVersion() {
|
16
|
+
try {
|
17
|
+
const p = require.resolve(`${pkgName}/package.json`, { paths: [process.cwd(), __dirname] });
|
18
|
+
return JSON.parse(fs.readFileSync(p, "utf8")).version;
|
19
|
+
} catch {
|
20
|
+
return null;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
async function checkAndUpdateVersion(callback) {
|
25
|
+
try {
|
26
|
+
logger("Đang kiểm tra phiên bản...", "info");
|
27
|
+
const latest = (await execPromise(`npm view ${pkgName} version`)).stdout.trim();
|
28
|
+
const installed = getInstalledVersion();
|
29
|
+
if (!installed || installed !== latest) {
|
30
|
+
logger(`Đã có bản mới (${latest}) Phiên bản đang dùng (${installed || "chưa cài"}). Đang cập nhật...`, "info");
|
31
|
+
try {
|
32
|
+
const { stderr } = await execPromise(`npm i ${pkgName}@latest`);
|
33
|
+
if (stderr) logger(stderr, "error");
|
34
|
+
logger(`Đã cập nhật fca lên phiên bản mới nhất: ${latest}, khởi động lại để áp dụng.`, "info");
|
35
|
+
callback(null);
|
36
|
+
} catch (e) {
|
37
|
+
logger(`Lỗi khi chạy npm install: ${e.error || e}. Đang thử tải về từ Github...`, "error");
|
38
|
+
try {
|
39
|
+
const { stderr } = await execPromise("npm i https://github.com/DongDev-VN/fca-unofficial");
|
40
|
+
if (stderr) logger(stderr, "error");
|
41
|
+
logger(`Đã tải về từ Github thành công: ${latest}`, "info");
|
42
|
+
callback(null);
|
43
|
+
} catch (gitErr) {
|
44
|
+
logger(`Lỗi khi tải về từ Github: ${gitErr.error || gitErr}`, "error");
|
45
|
+
callback(gitErr.error || gitErr);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
} else {
|
49
|
+
logger("Phiên bản đang dùng đã là mới nhất.", "info");
|
50
|
+
callback(null);
|
51
|
+
}
|
52
|
+
} catch (err) {
|
53
|
+
logger(`Lỗi khi kiểm tra phiên bản: ${err}`, "error");
|
54
|
+
callback(err);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
module.exports.checkAndUpdateVersion = checkAndUpdateVersion;
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
module.exports = require("./module/login");
|
1
|
+
module.exports = require("./module/login");
|
package/module/config.js
CHANGED
@@ -4,26 +4,31 @@ const logger = require("../func/logger");
|
|
4
4
|
const defaultConfig = {
|
5
5
|
autoUpdate: true,
|
6
6
|
mqtt: { enabled: true, reconnectInterval: 3600 },
|
7
|
-
|
8
|
-
password: "",
|
9
|
-
twofactor: "",
|
7
|
+
autoLogin: true,
|
8
|
+
credentials: { email: "", password: "", twofactor: "" }
|
10
9
|
};
|
10
|
+
|
11
11
|
function loadConfig() {
|
12
12
|
const configPath = path.join(process.cwd(), "fca-config.json");
|
13
13
|
let config;
|
14
14
|
if (!fs.existsSync(configPath)) {
|
15
|
-
|
16
|
-
|
15
|
+
try {
|
16
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
17
|
+
config = defaultConfig;
|
18
|
+
} catch (err) {
|
19
|
+
logger(`Error writing config file: ${err.message}`, "error");
|
20
|
+
config = defaultConfig;
|
21
|
+
}
|
17
22
|
} else {
|
18
23
|
try {
|
19
24
|
const fileContent = fs.readFileSync(configPath, "utf8");
|
20
|
-
config = JSON.parse(fileContent);
|
21
|
-
config = Object.assign({}, defaultConfig, config);
|
25
|
+
config = Object.assign({}, defaultConfig, JSON.parse(fileContent));
|
22
26
|
} catch (err) {
|
23
|
-
logger(
|
27
|
+
logger(`Error reading config file: ${err.message}`, "error");
|
24
28
|
config = defaultConfig;
|
25
29
|
}
|
26
30
|
}
|
27
31
|
return { config, configPath };
|
28
32
|
}
|
29
|
-
|
33
|
+
|
34
|
+
module.exports = { loadConfig, defaultConfig };
|
package/module/login.js
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
const utils = require("../src/utils");
|
3
3
|
const { setOptions } = require("./options");
|
4
4
|
const { loadConfig } = require("./config");
|
5
|
-
const loginHelper = require("./loginHelper");
|
6
5
|
const { config } = loadConfig();
|
6
|
+
if (config.autoUpdate) require("../func/checkUpdate").checkAndUpdateVersion(() => {});
|
7
7
|
global.fca = { config };
|
8
|
+
const loginHelper = require("./loginHelper");
|
9
|
+
|
8
10
|
function login(loginData, options, callback) {
|
9
11
|
if (utils.getType(options) === "Function" || utils.getType(options) === "AsyncFunction") {
|
10
12
|
callback = options;
|
@@ -42,4 +44,4 @@ function login(loginData, options, callback) {
|
|
42
44
|
loginHelper(loginData.appState, loginData.Cookie,loginData.email, loginData.password, globalOptions, callback, prCallback);
|
43
45
|
return returnPromise;
|
44
46
|
}
|
45
|
-
module.exports = login;
|
47
|
+
module.exports = login;
|
package/module/loginHelper.js
CHANGED
@@ -321,9 +321,9 @@ function setJarFromPairs(j, pairs, domain) {
|
|
321
321
|
|
322
322
|
function makeLogin(j, email, password, globalOptions, callback, prCallback) {
|
323
323
|
return async function () {
|
324
|
-
const u = email || config.email;
|
325
|
-
const p = password || config.password;
|
326
|
-
const tf = config.twofactor || null;
|
324
|
+
const u = email || config.credentials.email;
|
325
|
+
const p = password || config.credentials.password;
|
326
|
+
const tf = config.credentials.twofactor || null;
|
327
327
|
if (!u || !p) return;
|
328
328
|
const r = await tokens(u, p, tf);
|
329
329
|
if (r && r.status && Array.isArray(r.cookies)) {
|
@@ -392,10 +392,11 @@ async function tryAutoLoginIfNeeded(currentHtml, currentCookies, globalOptions)
|
|
392
392
|
if (uidB) return { html: htmlB, cookies: cookiesB, userID: uidB };
|
393
393
|
}
|
394
394
|
|
395
|
+
if (config.autoLogin !== true) throw new Error("AppState backup die — Auto-login is disabled");
|
395
396
|
logger("AppState backup die — proceeding to email/password login", "warn");
|
396
|
-
const u = config.email;
|
397
|
-
const p = config.password;
|
398
|
-
const tf = config.twofactor || null;
|
397
|
+
const u = config.credentials.email;
|
398
|
+
const p = config.credentials.password;
|
399
|
+
const tf = config.credentials.twofactor || null;
|
399
400
|
if (!u || !p) throw new Error("Missing user cookie");
|
400
401
|
const r = await tokens(u, p, tf);
|
401
402
|
if (!(r && r.status && Array.isArray(r.cookies))) throw new Error(r && r.message ? r.message : "Login failed");
|
@@ -631,4 +632,4 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback,
|
|
631
632
|
}
|
632
633
|
}
|
633
634
|
|
634
|
-
module.exports = loginHelper;
|
635
|
+
module.exports = loginHelper;
|
package/module/options.js
CHANGED
package/package.json
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
{
|
2
|
-
"name": "@dongdev/fca-unofficial",
|
3
|
-
"version": "2.0.
|
4
|
-
"description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
|
5
|
-
"main": "index.js",
|
6
|
-
"repository": {
|
7
|
-
"type": "git",
|
8
|
-
"url": "https://github.com/DongDev-VN/fca-unofficial.git"
|
9
|
-
},
|
10
|
-
"author": "Avery, David, Maude, Benjamin, UIRI, DongDev",
|
11
|
-
"license": "MIT",
|
12
|
-
"dependencies": {
|
13
|
-
"axios": "^1.12.2",
|
14
|
-
"axios-cookiejar-support": "^5.0.5",
|
15
|
-
"bluebird": "^3.7.2",
|
16
|
-
"chalk": "^4.1.2",
|
17
|
-
"cheerio": "^1.0.0-rc.10",
|
18
|
-
"duplexify": "^4.1.3",
|
19
|
-
"gradient-string": "^2.0.2",
|
20
|
-
"https-proxy-agent": "^4.0.0",
|
21
|
-
"mqtt": "^4.3.8",
|
22
|
-
"npmlog": "^1.2.0",
|
23
|
-
"request": "^2.53.0",
|
24
|
-
"sequelize": "^6.37.6",
|
25
|
-
"sqlite3": "^5.1.7",
|
26
|
-
"totp-generator": "^1.0.0",
|
27
|
-
"ws": "^8.18.1"
|
28
|
-
},
|
29
|
-
"devDependencies": {
|
30
|
-
"eslint": "^7.5.0",
|
31
|
-
"mocha": "^10.2.0",
|
32
|
-
"prettier": "^3.3.3"
|
33
|
-
},
|
34
|
-
"scripts": {
|
35
|
-
"test": "mocha",
|
36
|
-
"lint": "eslint . --ext .js,.cjs,.mjs,.ts,.tsx",
|
37
|
-
"prettier": "prettier \"**/*.{js,cjs,mjs,ts,tsx,json,md,css,scss,html,yml,yaml}\" --ignore-unknown --write"
|
38
|
-
},
|
39
|
-
"keywords": [
|
40
|
-
"facebook",
|
41
|
-
"chat",
|
42
|
-
"api",
|
43
|
-
"fca",
|
44
|
-
"facebook-chat-api"
|
45
|
-
],
|
46
|
-
"engines": {
|
47
|
-
"node": ">=10.x"
|
48
|
-
},
|
49
|
-
"types": "index.d.ts",
|
50
|
-
"homepage": "https://github.com/DongDev-VN/fca-unofficial#readme",
|
51
|
-
"bugs": {
|
52
|
-
"url": "https://github.com/DongDev-VN/fca-unofficial/issues"
|
53
|
-
},
|
54
|
-
"directories": {
|
55
|
-
"test": "test"
|
56
|
-
}
|
57
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@dongdev/fca-unofficial",
|
3
|
+
"version": "2.0.6",
|
4
|
+
"description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
|
5
|
+
"main": "index.js",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://github.com/DongDev-VN/fca-unofficial.git"
|
9
|
+
},
|
10
|
+
"author": "Avery, David, Maude, Benjamin, UIRI, DongDev, LunarKrystal",
|
11
|
+
"license": "MIT",
|
12
|
+
"dependencies": {
|
13
|
+
"axios": "^1.12.2",
|
14
|
+
"axios-cookiejar-support": "^5.0.5",
|
15
|
+
"bluebird": "^3.7.2",
|
16
|
+
"chalk": "^4.1.2",
|
17
|
+
"cheerio": "^1.0.0-rc.10",
|
18
|
+
"duplexify": "^4.1.3",
|
19
|
+
"gradient-string": "^2.0.2",
|
20
|
+
"https-proxy-agent": "^4.0.0",
|
21
|
+
"mqtt": "^4.3.8",
|
22
|
+
"npmlog": "^1.2.0",
|
23
|
+
"request": "^2.53.0",
|
24
|
+
"sequelize": "^6.37.6",
|
25
|
+
"sqlite3": "^5.1.7",
|
26
|
+
"totp-generator": "^1.0.0",
|
27
|
+
"ws": "^8.18.1"
|
28
|
+
},
|
29
|
+
"devDependencies": {
|
30
|
+
"eslint": "^7.5.0",
|
31
|
+
"mocha": "^10.2.0",
|
32
|
+
"prettier": "^3.3.3"
|
33
|
+
},
|
34
|
+
"scripts": {
|
35
|
+
"test": "mocha",
|
36
|
+
"lint": "eslint . --ext .js,.cjs,.mjs,.ts,.tsx",
|
37
|
+
"prettier": "prettier \"**/*.{js,cjs,mjs,ts,tsx,json,md,css,scss,html,yml,yaml}\" --ignore-unknown --write"
|
38
|
+
},
|
39
|
+
"keywords": [
|
40
|
+
"facebook",
|
41
|
+
"chat",
|
42
|
+
"api",
|
43
|
+
"fca",
|
44
|
+
"facebook-chat-api"
|
45
|
+
],
|
46
|
+
"engines": {
|
47
|
+
"node": ">=10.x"
|
48
|
+
},
|
49
|
+
"types": "index.d.ts",
|
50
|
+
"homepage": "https://github.com/DongDev-VN/fca-unofficial#readme",
|
51
|
+
"bugs": {
|
52
|
+
"url": "https://github.com/DongDev-VN/fca-unofficial/issues"
|
53
|
+
},
|
54
|
+
"directories": {
|
55
|
+
"test": "test"
|
56
|
+
}
|
57
|
+
}
|
package/.gitattributes
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
* text eol=lf
|