Skip to content

Commit fa957b5

Browse files
committed
fix
1 parent f08ebfd commit fa957b5

File tree

1 file changed

+32
-17
lines changed
  • scripts/backup/ext/fb-auto-invite-share/popup/helpers

1 file changed

+32
-17
lines changed

scripts/backup/ext/fb-auto-invite-share/popup/helpers/facebook.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { deepFindKeyInObject, getRedirectedUrl, sleep } from "./utils.js";
22

33
const CACHED = {
4-
uid: null,
5-
fb_dtsg: null,
4+
fb_dtsg: {},
65
urlToId: {},
76
};
87

98
export async function getMyUid() {
10-
if (CACHED.uid) return CACHED.uid;
11-
const d = await chrome.cookies.get({
12-
url: "https://www.facebook.com",
13-
name: "c_user",
14-
});
15-
CACHED.uid = d?.value;
16-
return CACHED.uid;
9+
for (let i of ["i_user", "c_user"]) {
10+
const d = await chrome.cookies.get({
11+
url: "https://www.facebook.com",
12+
name: i,
13+
});
14+
if (d?.value) return d?.value;
15+
}
16+
return null;
1717
}
1818

1919
export async function fetchGraphQl(params, url) {
@@ -76,7 +76,9 @@ export function wrapGraphQlParams(params = {}) {
7676
}
7777

7878
export async function getFbDtsg() {
79-
if (CACHED.fb_dtsg) return CACHED.fb_dtsg;
79+
const uid = await getMyUid();
80+
81+
if (CACHED.fb_dtsg[uid]) return CACHED.fb_dtsg[uid];
8082
let res = await fetch("https://mbasic.facebook.com/photos/upload/");
8183
let text = await res.text();
8284
let dtsg = RegExp(/name="fb_dtsg" value="(.*?)"/).exec(text)?.[1];
@@ -91,8 +93,8 @@ export async function getFbDtsg() {
9193
RegExp(/"dtsg":{"token":"([^"]+)"/).exec(text)?.[1] ||
9294
RegExp(/"name":"fb_dtsg","value":"([^"]+)/).exec(text)?.[1];
9395
}
94-
CACHED.fb_dtsg = dtsg || null;
95-
return CACHED.fb_dtsg;
96+
CACHED.fb_dtsg[uid] = dtsg || null;
97+
return CACHED.fb_dtsg[uid];
9698
}
9799

98100
export function findDataObject(object) {
@@ -236,6 +238,7 @@ export async function getEntityAbout(entityID, context = "DEFAULT") {
236238
doc_id: "7257793420991802",
237239
});
238240
const json = JSON.parse(res);
241+
console.log(json);
239242
const node = json.data.node;
240243
if (!node) throw new Error("Wrong ID / Entity not found");
241244
const typeText = node.__typename.toLowerCase();
@@ -289,7 +292,21 @@ export async function sharePostToGroup({
289292
if (!groupId) {
290293
throw new Error("Không lấy được group id");
291294
}
292-
console.log("group", groupId, "postOwner", postOwner, "post", postId);
295+
const myUid = await getMyUid();
296+
const me = await getEntityAbout(myUid);
297+
if (!me) {
298+
throw new Error("Không lấy được thông tin nick của bạn");
299+
}
300+
console.log(
301+
"group",
302+
groupId,
303+
"postOwner",
304+
postOwner,
305+
"post",
306+
postId,
307+
"me",
308+
me
309+
);
293310

294311
const res = await fetchGraphQl({
295312
fb_api_req_friendly_name: "ComposerStoryCreateMutation",
@@ -307,10 +324,8 @@ export async function sharePostToGroup({
307324
attachments: [
308325
{
309326
link: {
310-
// group -> group: 37
311-
// page -> group: 22
312327
share_scrape_data: JSON.stringify({
313-
share_type: postOwner.type === TargetType.Group ? 37 : 22,
328+
share_type: me.type === TargetType.Page ? 37 : 22,
314329
share_params: [postId],
315330
}),
316331
},
@@ -357,7 +372,7 @@ export async function sharePostToGroup({
357372
__relay_internal__pv__StoriesArmadilloReplyEnabledrelayprovider: true,
358373
__relay_internal__pv__EventCometCardImage_prefetchEventImagerelayprovider: false,
359374
},
360-
doc_id: "8148691861851794",
375+
doc_id: "8358507460852422",
361376
});
362377
const json = JSON.parse(res?.split?.("\n")?.[0]);
363378
console.log(json);

0 commit comments

Comments
 (0)