-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathindex.js
More file actions
161 lines (160 loc) · 4.65 KB
/
index.js
File metadata and controls
161 lines (160 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const express = require('express');
const axios = require('axios');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
app.use(express.json());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
const total = new Map();
app.get('/total', (req, res) => {
const data = Array.from(total.values()).map((link, index) => ({
session: index + 1,
url: link.url,
count: link.count,
id: link.id,
target: link.target,
}));
res.json(JSON.parse(JSON.stringify(data || [], null, 2)));
});
app.get('/', (res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.post('/api/submit', async (req, res) => {
const {
cookie,
url,
amount,
interval,
} = req.body;
if (!cookie || !url || !amount || !interval) return res.status(400).json({
error: 'Missing state, url, amount, or interval'
});
try {
const cookies = await convertCookie(cookie);
if (!cookies) {
return res.status(400).json({
status: 500,
error: 'Invalid cookies'
});
};
await share(cookies, url, amount, interval)
res.status(200).json({
status: 200
});
} catch (err) {
return res.status(500).json({
status: 500,
error: err.message || err
});
}
});
async function share(cookies, url, amount, interval) {
const id = await getPostID(url);
const accessToken = await getAccessToken(cookies);
if (!id) {
throw new Error("Unable to get link id: invalid URL, it's either a private post or visible to friends only");
}
const postId = total.has(id) ? id + 1 : id;
total.set(postId, {
url,
id,
count: 0,
target: amount,
});
const headers = {
'accept': '*/*',
'accept-encoding': 'gzip, deflate',
'connection': 'keep-alive',
'content-length': '0',
'cookie': cookies,
'host': 'graph.facebook.com'
};
let sharedCount = 0;
let timer;
async function sharePost() {
try {
const response = await axios.post(`https://graph.facebook.com/me/feed?link=https://m.facebook.com/${id}&published=0&access_token=${accessToken}`, {}, {
headers
});
if (response.status !== 200) {
} else {
total.set(postId, {
...total.get(postId),
count: total.get(postId).count + 1,
});
sharedCount++;
}
if (sharedCount === amount) {
clearInterval(timer);
}
} catch (error) {
clearInterval(timer);
total.delete(postId);
}
}
timer = setInterval(sharePost, interval * 1000);
setTimeout(() => {
clearInterval(timer);
total.delete(postId);
}, amount * interval * 1000);
}
async function getPostID(url) {
try {
const response = await axios.post('https://id.traodoisub.com/api.php', `link=${encodeURIComponent(url)}`, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
return response.data.id;
} catch (error) {
return;
}
}
async function getAccessToken(cookie) {
try {
const headers = {
'authority': 'business.facebook.com',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-language': 'vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5',
'cache-control': 'max-age=0',
'cookie': cookie,
'referer': 'https://www.facebook.com/',
'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
};
const response = await axios.get('https://business.facebook.com/content_management', {
headers
});
const token = response.data.match(/"accessToken":\s*"([^"]+)"/);
if (token && token[1]) {
const accessToken = token[1];
return accessToken;
}
} catch (error) {
return;
}
}
async function convertCookie(cookie) {
return new Promise((resolve, reject) => {
try {
const cookies = JSON.parse(cookie);
const sbCookie = cookies.find(cookies => cookies.key === "sb");
if (!sbCookie) {
reject("Detect invalid appstate please provide a valid appstate");
}
const sbValue = sbCookie.value;
const data = `sb=${sbValue}; ${cookies.slice(1).map(cookies => `${cookies.key}=${cookies.value}`).join('; ')}`;
resolve(data);
} catch (error) {
reject("Error processing appstate please provide a valid appstate");
}
});
}
app.listen(5000)