@dongdev/fca-unofficial 2.0.12 → 2.0.14

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.
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const logger = require('../../func/logger');
2
3
 
3
4
  function saveCookies(jar) {
4
5
  return res => {
@@ -77,6 +78,41 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
77
78
  return cfg?.url || "";
78
79
  }
79
80
  };
81
+
82
+ const formatCookie = (arr, service) => {
83
+ const n = String(arr?.[0] || "");
84
+ const v = String(arr?.[1] || "");
85
+ return `${n}=${v}; Domain=.${service}.com; Path=/; Secure`;
86
+ };
87
+
88
+ const maybeAutoLogin = async (resData) => {
89
+ if (ctx.auto_login) {
90
+ const e = new Error("Not logged in.");
91
+ e.error = "Not logged in.";
92
+ e.res = resData;
93
+ throw e;
94
+ }
95
+ if (typeof ctx.performAutoLogin !== "function") {
96
+ const e = new Error("Not logged in.");
97
+ e.error = "Not logged in.";
98
+ e.res = resData;
99
+ throw e;
100
+ }
101
+ ctx.auto_login = true;
102
+ logL("Phiên đăng nhập hết hạn", "warn");
103
+ const ok = await ctx.performAutoLogin();
104
+ if (ok) {
105
+ logL("Auto login successful! Restarting...", "AUTO-LOGIN");
106
+ ctx.auto_login = false;
107
+ process.exit(1);
108
+ } else {
109
+ ctx.auto_login = false;
110
+ const e = new Error("Not logged in.");
111
+ e.error = "Not logged in.";
112
+ e.res = resData;
113
+ throw e;
114
+ }
115
+ };
80
116
  return async (res) => {
81
117
  const status = res?.status ?? 0;
82
118
  if (status >= 500 && status < 600) {
@@ -90,11 +126,16 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
90
126
  const retryTime = Math.floor(Math.random() * 5000);
91
127
  await delay(retryTime);
92
128
  const url = buildUrl(res?.config);
129
+ const method = String(res?.config?.method || "GET").toUpperCase();
93
130
  const ctype = String(headerOf(res?.config?.headers, "content-type") || "").toLowerCase();
94
131
  const isMultipart = ctype.includes("multipart/form-data");
95
132
  const payload = res?.config?.data;
96
133
  const params = res?.config?.params;
97
134
  retryCount += 1;
135
+ if (method === "GET") {
136
+ const newData = await http.get(url, ctx.jar, params || null, ctx.globalOptions, ctx);
137
+ return await parseAndCheckLogin(ctx, http, retryCount)(newData);
138
+ }
98
139
  if (isMultipart) {
99
140
  const newData = await http.postFormData(url, ctx.jar, payload, params, ctx.globalOptions, ctx);
100
141
  return await parseAndCheckLogin(ctx, http, retryCount)(newData);
@@ -123,17 +164,17 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
123
164
  throw err;
124
165
  }
125
166
  const method = String(res?.config?.method || "GET").toUpperCase();
126
- if (parsed.redirect && method === "GET") {
167
+ if (parsed?.redirect && method === "GET") {
127
168
  const redirectRes = await http.get(parsed.redirect, ctx.jar, null, ctx.globalOptions, ctx);
128
169
  return await parseAndCheckLogin(ctx, http)(redirectRes);
129
170
  }
130
- if (parsed.jsmods && parsed.jsmods.require && Array.isArray(parsed.jsmods.require[0]) && parsed.jsmods.require[0][0] === "Cookie") {
131
- parsed.jsmods.require[0][3][0] = parsed.jsmods.require[0][3][0].replace("_js_", "");
171
+ if (parsed?.jsmods && parsed.jsmods.require && Array.isArray(parsed.jsmods.require[0]) && parsed.jsmods.require[0][0] === "Cookie") {
172
+ parsed.jsmods.require[0][3][0] = String(parsed.jsmods.require[0][3][0] || "").replace("_js_", "");
132
173
  const requireCookie = parsed.jsmods.require[0][3];
133
- ctx.jar.setCookie(formatCookie(requireCookie, "facebook"), "https://www.facebook.com");
134
- ctx.jar.setCookie(formatCookie(requireCookie, "messenger"), "https://www.messenger.com");
174
+ await ctx.jar.setCookie(formatCookie(requireCookie, "facebook"), "https://www.facebook.com");
175
+ await ctx.jar.setCookie(formatCookie(requireCookie, "messenger"), "https://www.messenger.com");
135
176
  }
136
- if (parsed.jsmods && Array.isArray(parsed.jsmods.require)) {
177
+ if (parsed?.jsmods && Array.isArray(parsed.jsmods.require)) {
137
178
  for (const item of parsed.jsmods.require) {
138
179
  if (item[0] === "DTSG" && item[1] === "setToken") {
139
180
  ctx.fb_dtsg = item[3][0];
@@ -143,11 +184,26 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
143
184
  }
144
185
  }
145
186
  }
146
- if (parsed.error === 1357001) {
187
+ if (parsed?.error === 1357001) {
147
188
  const err = new Error("Facebook blocked the login");
148
189
  err.error = "Not logged in.";
149
190
  throw err;
150
191
  }
192
+ const resData = parsed;
193
+ const resStr = JSON.stringify(resData);
194
+ if (resStr.includes("XCheckpointFBScrapingWarningController") || resStr.includes("601051028565049")) {
195
+ await maybeAutoLogin(resData);
196
+ }
197
+ if (resStr.includes("https://www.facebook.com/login.php?") || String(parsed?.redirect || "").includes("login.php?")) {
198
+ await maybeAutoLogin(resData);
199
+ }
200
+ if (resStr.includes("1501092823525282")) {
201
+ logger("Bot checkpoint 282 detected, please check the account!", "error");
202
+ process.exit(0);
203
+ }
204
+ if (resStr.includes("828281030927956")) {
205
+ logger("Bot checkpoint 956 detected, please check the account!", "error");
206
+ }
151
207
  return parsed;
152
208
  };
153
209
  }
package/func/login.js DELETED
File without changes