Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threads integration updating verifyLInk api / answerAbos and tiktok api v2 #289

Merged
merged 9 commits into from
Jul 17, 2023
28 changes: 28 additions & 0 deletions controllers/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
updateFacebookPages,
tiktokAbos,
getFacebookUsername,
verifyThread,
} = require('../manager/oracles')

//var ejs = require('ejs')
Expand Down Expand Up @@ -884,6 +885,20 @@ module.exports.confrimChangeMail = async (req, res) => {
}
}

module.exports.checkInsta = async (req, res) => {
try{
let instaAccount = await FbPage.exists({UserId : req.user._id, instagram_username : {$exists : true}});
return makeResponseData(res, 201, instaAccount)

}catch (err) {
return makeResponseError(
res,
500,
err.message ? err.message : err.error
)
}
}

module.exports.verifyLink = async (req, response) => {
try {
var userId = req.user._id
Expand Down Expand Up @@ -1002,6 +1017,19 @@ module.exports.verifyLink = async (req, response) => {
if (res === 'deactivate') deactivate = true
}

break
case '7':
const {threads_id} = await FbPage.findOne({
UserId: userId,
instagram_id: { $exists: true } ,
threads_id: { $exists: true }
},{threads_id : 1}).lean()
if (threads_id) {
linked = true
res = await verifyThread(idPost,threads_id)
if (res === 'deactivate') deactivate = true
}

break
default:
}
Expand Down
100 changes: 84 additions & 16 deletions manager/oracles.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,48 @@
}
}

exports.verifyThread = async (idPost, threads_id) => {
try {
const res = await axios.get(`https://www.threads.net/t/${idPost}`);
Fixed Show fixed Hide fixed

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.

let text = res.data;
text = text.replace(/\s/g, '');
text = text.replace(/\n/g, '');

const postID = text.match(/{"post_id":"(.*?)"}/)?.[1];
const lsdToken = text.match(/"LSD",\[\],{"token":"(\w+)"},\d+\]/)?.[1];

// THIS FUNCTION WILL GIVE US IF ACCOUNT EXIST OR NO ( TO LINK SATT ACCOUNT TO THREAD ACCOUNT )
const headers = {
'Authority': 'www.threads.net',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://www.threads.net',
'Pragma': 'no-cache',
'Sec-Fetch-Site': 'same-origin',
'X-ASBD-ID': '129477',
'X-FB-LSD': lsdToken,
'X-IG-App-ID': '238260118697367',
};

const response = await axios.post("https://www.threads.net/api/graphql", {
'lsd': lsdToken,
'variables': JSON.stringify({
postID,
}),
'doc_id': '5587632691339264',
}, {
headers
});
let owner =response.data.data.data.containing_thread.thread_items[0].post.user.pk
return threads_id === owner;

} catch (err) {
return 'lien_invalid'
}
}
exports.verifyTwitter = async function (twitterProfile, userId, idPost) {
try {
const client = new Twitter({
Expand Down Expand Up @@ -306,6 +348,8 @@
tiktokProfile.followers = res ?? 0
await tiktokProfile.save()
break
case '7':
var res = await threadsAbos(idPost,id)
default:
var res = 0
break
Expand Down Expand Up @@ -473,6 +517,28 @@
}
}


const threadsAbos = async (idPost, id, userName) => {
try {
var followers = 0
var campaign_link = await CampaignLink.findOne({ idPost }).lean()

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.


let instagramUserName = campaign_link?.instagramUserName || userName
var fbPage = await FbPage.findOne({
UserId: id ,
instagram_username: instagramUserName ,
instagram_id: { $exists: true } ,
threads_id: { $exists: true }
})

if (fbPage) {

}
return followers
} catch (err) {}
}

exports.getPromApplyStats = async (
oracles,
link,
Expand Down Expand Up @@ -721,22 +787,24 @@
let getUrl = `https://open-api.tiktok.com/oauth/refresh_token?client_key=${process.env.TIKTOK_KEY}&grant_type=refresh_token&refresh_token=${tiktokProfile.refreshToken}`
let resMedia = await rp.get(getUrl)
resMedia?.data?.data?.access_token && await TikTokProfile.updateOne({_id:tiktokProfile._id},{accessToken : resMedia?.data?.data.access_token})
let videoInfoResponse = await axios
.post('https://open-api.tiktok.com/video/query/', {
access_token: resMedia?.data?.data.access_token,
open_id: tiktokProfile.userTiktokId,
filters: {
video_ids: [idPost],
},
fields: [
'like_count',
'comment_count',
'share_count',
'view_count',
'cover_image_url',
],
})
.then((response) => response.data)
const data = {
filters: {
video_ids: [
idPost
]
}
};

let videoInfoResponse = await axios({
method: 'post',
url: 'https://open.tiktokapis.com/v2/video/query/?fields=id,title',
headers: {
'Authorization': "Bearer " +resMedia?.data?.data.access_token,
'Content-Type': 'application/json'
},
data
}).then((response) => response.data)


return {
likes: videoInfoResponse.data.videos[0].like_count,
Expand Down
1 change: 1 addition & 0 deletions model/fbPage.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fbPageSchema = mongoose.Schema(
UserId: { type: Number, required: true, ref: 'user' },
id: { type: String },
instagram_id: { type: String },
threads_id : String,
instagram_username: { type: String },
name: { type: String },
picture: { type: String },
Expand Down
3 changes: 3 additions & 0 deletions routes/profile.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
ShareByActivity,
tiktokApiAbos,
ProfilPrivacy,
checkInsta
} = require('../controllers/profile.controller')
const {
addFacebookChannel,
Expand Down Expand Up @@ -1329,7 +1330,7 @@
* "500":
* description: error:<br> server error
*/
router.get('/link/verify/:typeSN/:idUser/:idPost', verifyAuth, verifyLinkValidation,verifyLink)

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.

/**
* @swagger
Expand Down Expand Up @@ -1393,4 +1394,6 @@
router.get('/Tiktok/ProfilPrivacy', verifyAuth, ProfilPrivacy)


router.get('/check/insta',verifyAuth,checkInsta)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

module.exports = router