From 3f91c182444b9c43126920ec5cbd5b4875045227 Mon Sep 17 00:00:00 2001 From: raniamorheg Date: Wed, 26 Jul 2023 17:00:20 +0100 Subject: [PATCH 1/2] fix add threads account --- controllers/profile.controller.js | 7 ++++--- routes/profile.routes.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/controllers/profile.controller.js b/controllers/profile.controller.js index 810549ed..307bab9d 100644 --- a/controllers/profile.controller.js +++ b/controllers/profile.controller.js @@ -1157,6 +1157,7 @@ module.exports.ProfilPrivacy = async (req, res) => { module.exports.addThreadsAccount = async (req,res) => { try { + let tt = req.user._id const instaAccount = await FbPage.findOne({UserId : req.user._id, instagram_username : {$exists : true}}); if(!instaAccount) return makeResponseData(res, 200,'instagram_not_found') if(instaAccount.threads_id) return makeResponseData(res, 200,'threads_already_added') @@ -1164,13 +1165,13 @@ module.exports.addThreadsAccount = async (req,res) => { let text = user.data.replace(/\s/g, '').replace(/\s/g, ''); const userID = text.match(/"user_id":"(\d+)"/)?.[1] if(!userID) return makeResponseData(res, 200,'threads_not_found') - const followers = extractFollowerCount(user.data.split('Followers')[0].split("content=").at(-1).trim()) + const followers = extractFollowerCount(user.data.split('Followers')[0].split("content=")[user.data.split('Followers')[0].split("content=").length - 1].trim()) const lsdToken = await getLsdToken(text) const currentUser = await fetchUserThreadData(lsdToken, userID); if(currentUser) { const userPicture = await axios.get(currentUser.profile_pic_url, { responseType: 'arraybuffer' }) const base64String = Buffer.from(userPicture.data, 'binary').toString('base64'); - await FbPage.updateOne({ + await FbPage.updateOne({UserId : req.user._id, instagram_username: instaAccount.instagram_username, }, {threads_id: currentUser.pk, threads_picture: base64String ? base64String : currentUser.profile_pic_url, threads_followers : followers}) return makeResponseData(res, 200, 'threads_account_added', {username: instaAccount.instagram_username, picture: base64String ? base64String : currentUser.profile_pic_url, id: currentUser.pk,threads_followers : followers}) @@ -1234,7 +1235,7 @@ module.exports.removeThreadsAccount = async (req, res) => { const getLsdToken = async (text) => { - const lsdTokenMatch = text.match(/"LSD",\[\],{"token":"(\w+)"},\d+\]/)?.[1]; + const lsdTokenMatch = await text.match(/"LSD",\[\],{"token":"(\w+)"},\d+\]/)?.[1]; return lsdTokenMatch; }; diff --git a/routes/profile.routes.js b/routes/profile.routes.js index d392044c..7df47660 100644 --- a/routes/profile.routes.js +++ b/routes/profile.routes.js @@ -1396,10 +1396,26 @@ router.get('/linkedin/ShareByActivity/:activity', verifyAuth, ShareByActivityVal */ router.get('/Tiktok/ProfilPrivacy', verifyAuth, ProfilPrivacy) +/** + * @swagger + * /profile/add/threads-account: + * get: + * tags: + * - "profile" + * summary: add threads account. + * responses: + * "200": + * description: data:{"code":"200","message":"success","data":""} + * "401": + * description: error:
Invalid Access Token + * "500": + * description: error:
server error + */ +router.get('/add/threads-account', verifyAuth, addThreadsAccount) router.get('/check/threads-account',verifyAuth,checkThreads) -router.get('/add/threads-account', verifyAuth, addThreadsAccount) + router.delete('/remove/threads-account/:id', verifyAuth, idThreadsAccountValidation,removeThreadsAccount) From 51428a57e35f30eab753d0331f8c962239a1c249 Mon Sep 17 00:00:00 2001 From: HamdiBenK <78487156+HamdiBenK@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:01:00 +0100 Subject: [PATCH 2/2] Update profile.controller.js --- controllers/profile.controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/profile.controller.js b/controllers/profile.controller.js index 307bab9d..6e1178fb 100644 --- a/controllers/profile.controller.js +++ b/controllers/profile.controller.js @@ -1157,7 +1157,6 @@ module.exports.ProfilPrivacy = async (req, res) => { module.exports.addThreadsAccount = async (req,res) => { try { - let tt = req.user._id const instaAccount = await FbPage.findOne({UserId : req.user._id, instagram_username : {$exists : true}}); if(!instaAccount) return makeResponseData(res, 200,'instagram_not_found') if(instaAccount.threads_id) return makeResponseData(res, 200,'threads_already_added')