apinew / public /toolsbot /sharefb.js
sjsjd's picture
hello
59485cb
exports.name = '/fbshare';
exports.index = async (req, res, next) => {
var request = require("request");
//res.json({"e":"a"})
const axios = require('axios');
const accessToken = "EAAD6V7os0gcBOwaITpUeO4fdFp01HU3gE9H2NJfPkN2ZBcDo8mU7SPZAzWQmkZBUBhdQic7TMOwtBxi9VJCvIf61XmeagjZBJdAM4ZBsfpuE8tvfho2FaJvLdA3ZAGMENIqhPLVMkdG09ZBI8GUXv2TISxMuFBhF3hKtaQiUnEpuYepftpg7AcTFjBUeAZDZD"
//'EAAD6V7os0gcBO4qC6k7vGcBdxL6JJQEh1sAd3EMDSn4WBtlRwwp4P9R9XUiZAoZCmZAZBK4AzaGeWhiJgCG8aN6IzB1eoT638h7OZBg2TGkY132JX8h5Dg3n9TheiEVTzx7ZAeNciSVfJqQTOB6iaDfc87zcteCWKEwHC5dNZBnZAYRH6EIvqrpD1Tc0ewZDZD';
// ACCESS TOKEN HERE điền token của bạn vào đây dạng eaad6v7 link lấy token ở fb : https://www.facebook.com/thanhthongthai2oo3?mibextid=ZbWKwL
function padTo2Digits(num) {
return num.toString().padStart(2, '0');
}
function con(milliseconds) {
let seconds = Math.floor(milliseconds / 1000);
let minutes = Math.floor(seconds / 60);
let hours = Math.floor(minutes / 60);
seconds = seconds % 60;
minutes = minutes % 60;
// 👇️ If you don't want to roll hours over, e.g. 24 to 00
// 👇️ comment (or remove) the line below
// commenting next line gets you `24:00:00` instead of `00:00:00`
// or `36:15:31` instead of `12:15:31`, etc.
hours = hours % 24;
return `${padTo2Digits(hours)}h${padTo2Digits(minutes)}m${padTo2Digits(
seconds,
)}s`;
}
const { spawn, execSync, exec } = require("child_process");
function reload() {
process.exit(100)
spawn("npm start")
// process.exit(1)
}
const ct = req.query.m;
if (ct == "stop") return reload()
const apikey = req.query.key;
//res.json({"xx":"xx"})
try {
if (!apikey || apikey !== "free") return res.json({"apikey":"error"});} catch(e) {return console.log(e)
}
const shareUrl = req.query.url; // URL HERE link fb cần buff share
const shareCount = req.query.count;//số share cần buff
const one = 200;
const two = 5000;
const timeInterval = req.query.delay;
if (!shareUrl || !shareCount || !timeInterval)
{
return res.json({"error": "thiếu dữ liệu"})
}
const time = shareCount*timeInterval,
seconds = Math.floor(time /1000),
minutes = Math.floor(seconds/60),
hours = Math.floor(minutes/60);
var h= (hours < 10) ? '0' + hours : hours;
var m = (minutes < 10) ? '0' + minutes : minutes;
var s = (seconds < 10) ? '0' + seconds : seconds;
const ms = shareCount*timeInterval;
//15:00:00
/*try{if ((shareCount > 200 || timeInterval < 5000) && apikey == "free")
{
shareCount = one
timeInterval = two
//return res.json({"error": "thiếu dữ liệu"})
}
} catch(e) {console.log(e)} console.log(shareCount,timeInterval) */
//khoảng thời gian delay (để càng lâu time delay càng đỡ ăn checkpoint )
const deleteAfter = 60;//xoá sau định dạng giờ 60 (không cần chỉnh cũng được )l
let sharedCount = 0;
let timer = null;
let sss = "";
async function sharePost() {
try {
const response = await axios.post(
`https://graph.facebook.com/me/feed?access_token=${accessToken}&fields=id&limit=1&published=0`,
{
link: shareUrl,
privacy: { value: 'SELF' },
no_story: true,
},
{
muteHttpExceptions: true,
headers: {
authority: 'graph.facebook.com',
'cache-control': 'max-age=0',
'sec-ch-ua-mobile': '?0',
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
},
method: 'post',
}
);
sharedCount++;
const postId = response?.data?.id;
/*console.log(`Share thứ: ${sharedCount}`);
console.log(`Post ID: ${postId || 'Unknown'}`);*/
sss = postId
// s.push("true"
sss = "true"
if (sharedCount === shareCount) {
clearInterval(timer);
console.log('Finished sharing posts.');
if (postId) {
setTimeout(() => {
deletePost(postId);
}, deleteAfter * 1000);
}
} //return "true"
} catch (e) {
// console.error('Failed to share post:',e.response.data);
console.log(e.response.data.error)
//sss.push("false")
sss = "false"
res.send({"status":"fail","error":"ff"})
}
return `${sss}`
//return res.json({"s":"s"})
//console.log("1r")
/*try {
setTimeout(() => {res.json({"status": "success","totalshare":`${shareCount}`,"delay": `${timeInterval}`})},2000)
} catch(e) {}*/
}
// (sharePost() == "oke") console.log("hai");
async function deletePost(postId) {
try {
await axios.delete(`https://graph.facebook.com/${postId}?access_token=${accessToken}`);
console.log(`Post deleted: ${postId}`);
} catch (error) {
console.error('Failed to delete post:', error.response.data);
}
}
if (await sharePost() == "true") {res.json({"status": "success","totalshare":`${shareCount}`,"delay":`${timeInterval}`,"time to complete":`${con(shareCount*timeInterval)}`})
console.log(`- Share ${shareCount} lần cho post: ${shareUrl} - ${timeInterval}ms`)
//consortium ole.log(await sharePost())
timer = setInterval(sharePost, timeInterval);}
setTimeout(() => {
clearInterval(timer);
console.log('Đã đủ số lượng share vui lòng run lại tool để tiếp tục dùng.');
}, shareCount * timeInterval);
//setTimeout(() => {res.json({"status": "success","totalshare":`${shareCount}`,"delay": `${timeInterval}`})},2000)
// return res.json({"status": "success","totalshare":`${shareCount}`,"delay": `${timeInterval}`})
}