diff --git a/controllers/profile.controller.js b/controllers/profile.controller.js
index 810549ed..6e1178fb 100644
--- a/controllers/profile.controller.js
+++ b/controllers/profile.controller.js
@@ -1164,13 +1164,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 +1234,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)