From a758b3a4b333f0f653dbd2f29f0fff503d41e617 Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Fri, 3 Jan 2025 17:53:35 +0900 Subject: [PATCH] refactor: rename --- src/lib/bskyHelpers.ts | 35 ++++++++++++---------------- src/lib/searchBskyUsers.ts | 6 +++-- src/lib/services/instagramService.ts | 2 +- src/lib/services/threadsService.ts | 2 +- src/lib/services/xService.ts | 4 ++-- src/types.ts | 2 +- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/lib/bskyHelpers.ts b/src/lib/bskyHelpers.ts index cea2ed2..b696601 100644 --- a/src/lib/bskyHelpers.ts +++ b/src/lib/bskyHelpers.ts @@ -1,16 +1,12 @@ import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; +import type { CrawledUserInfo } from "~types"; import { BSKY_PROFILE_LABEL, BSKY_USER_MATCH_TYPE } from "./constants"; -type xUserInfo = { - bskyHandleInDescription: string; - accountName: string; - accountNameRemoveUnderscore: string; - accountNameReplaceUnderscore: string; - displayName: string; -}; - export const isSimilarUser = ( - xUserInfo: xUserInfo, + crawledUserInfo: Omit< + CrawledUserInfo, + "originalAvatar" | "originalProfileLink" + >, bskyProfile: ProfileView | undefined, ): { isSimilar: boolean; @@ -24,10 +20,10 @@ export const isSimilarUser = ( } // this is to handle the case where the user has a bsky handle in their description - if (xUserInfo.bskyHandleInDescription) { + if (crawledUserInfo.bskyHandleInDescription) { const formattedBskyHandle = bskyProfile.handle.replace("@", ""); const formattedBskyHandleInDescription = - xUserInfo.bskyHandleInDescription.replace("@", ""); + crawledUserInfo.bskyHandleInDescription.replace("@", ""); if ( formattedBskyHandle === formattedBskyHandleInDescription || formattedBskyHandle.includes(formattedBskyHandleInDescription) @@ -39,16 +35,15 @@ export const isSimilarUser = ( } } - const lowerCaseNames = Object.entries(xUserInfo).reduce( - (acc, [key, value]) => { - if (!value) { - return acc; - } - acc[key] = value.toLowerCase(); + const lowerCaseNames = Object.entries( + crawledUserInfo, + ).reduce((acc, [key, value]) => { + if (!value) { return acc; - }, - {} as xUserInfo, - ); + } + acc[key] = value.toLowerCase(); + return acc; + }, {} as CrawledUserInfo); const bskyHandle = bskyProfile.handle .toLocaleLowerCase() diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index 45b0f40..d8e260a 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -12,7 +12,9 @@ export const searchBskyUser = async ({ userData: CrawledUserInfo; }) => { const searchTerms = [ - ...(userData.bskyHandle ? [userData.bskyHandle] : []), + ...(userData.bskyHandleInDescription + ? [userData.bskyHandleInDescription] + : []), userData.accountNameRemoveUnderscore, userData.accountNameReplaceUnderscore, userData.displayName, @@ -39,7 +41,7 @@ export const searchBskyUser = async ({ const { isSimilar: isUserFound, type } = isSimilarUser( // TODO: simplify { - bskyHandleInDescription: userData.bskyHandle, + bskyHandleInDescription: userData.bskyHandleInDescription, accountName: userData.accountName, accountNameRemoveUnderscore: userData.accountNameRemoveUnderscore, accountNameReplaceUnderscore: userData.accountNameReplaceUnderscore, diff --git a/src/lib/services/instagramService.ts b/src/lib/services/instagramService.ts index fe40f97..e0ef9c6 100644 --- a/src/lib/services/instagramService.ts +++ b/src/lib/services/instagramService.ts @@ -66,7 +66,7 @@ export class InstagramService implements IService { displayName, accountNameRemoveUnderscore, accountNameReplaceUnderscore, - bskyHandle: "", + bskyHandleInDescription: "", originalAvatar: avatarSrc, originalProfileLink: `https://www.instagram.com/${_accountName}`, }; diff --git a/src/lib/services/threadsService.ts b/src/lib/services/threadsService.ts index 18fb228..e87537b 100644 --- a/src/lib/services/threadsService.ts +++ b/src/lib/services/threadsService.ts @@ -71,7 +71,7 @@ export class ThreadsService implements IService { displayName, accountNameRemoveUnderscore, accountNameReplaceUnderscore, - bskyHandle: "", + bskyHandleInDescription: "", originalAvatar: avatarSrc, originalProfileLink: `https://www.threads.net/@${_accountName}`, }; diff --git a/src/lib/services/xService.ts b/src/lib/services/xService.ts index 8cbe4b5..cb3377f 100644 --- a/src/lib/services/xService.ts +++ b/src/lib/services/xService.ts @@ -46,7 +46,7 @@ export class XService implements IService { const accountNameRemoveUnderscore = accountName.replaceAll("_", ""); // bsky does not allow underscores in handle, so remove them. const accountNameReplaceUnderscore = accountName.replaceAll("_", "-"); const displayName = displayNameEl?.textContent; - const bskyHandle = + const bskyHandleInDescription = userCell.textContent?.match( new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`), )?.[1] ?? @@ -64,7 +64,7 @@ export class XService implements IService { displayName, accountNameRemoveUnderscore, accountNameReplaceUnderscore, - bskyHandle, + bskyHandleInDescription, originalAvatar, originalProfileLink: `https://x.com/${accountName}`, }; diff --git a/src/types.ts b/src/types.ts index fac2894..dbb26a0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -38,7 +38,7 @@ export type CrawledUserInfo = { displayName: string; accountNameRemoveUnderscore: string; accountNameReplaceUnderscore: string; - bskyHandle: string; + bskyHandleInDescription: string; originalAvatar: string; originalProfileLink: string; };