Skip to content

Commit

Permalink
fix add threads account (#297)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
HamdiBenK committed Jul 27, 2023
2 parents d6b8007 + 51428a5 commit 2fa0a13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions controllers/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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;
};

Expand Down
18 changes: 17 additions & 1 deletion routes/profile.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br> Invalid Access Token
* "500":
* description: error:<br> 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)

Expand Down

0 comments on commit 2fa0a13

Please sign in to comment.