From eaa6b88ecb5203e8bcfce48e3bb6c7a88ed378b2 Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Tue, 3 Oct 2023 10:02:58 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20non=20query=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/searchAndInsertBskyUsers.ts | 35 ++++++++++++++++------------- src/lib/utils.ts | 4 ++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/lib/searchAndInsertBskyUsers.ts b/src/lib/searchAndInsertBskyUsers.ts index 16c5200..7784236 100644 --- a/src/lib/searchAndInsertBskyUsers.ts +++ b/src/lib/searchAndInsertBskyUsers.ts @@ -1,7 +1,7 @@ import { isOutOfTopViewport, removeReloadEl } from './domHelpers'; import { getAccountNameAndDisplayName, getUserCells, insertBskyProfileEl, insertNotFoundEl, insertReloadEl } from "~lib/domHelpers"; import { isSimilarUser } from "~lib/bskyHelpers"; -import { debugLog } from "~lib/utils"; +import { debugLog, isOneSymbol } from "~lib/utils"; import type { BskyClient } from './bskyClient'; import type { ViewerState } from '@atproto/api/dist/client/types/app/bsky/actor/defs'; import type { UserCellBtnLabel } from './components/BskyUserCell'; @@ -62,24 +62,29 @@ export const searchAndInsertBskyUsers = async ( // Loop over search parameters and break if a user is found for (const term of searchTerms) { - if (!term) { + // one symbol is not a valid search term for bsky + if (!term || isOneSymbol(term)) { continue } - const [searchResult] = await agent.searchUser({ - term: term, - limit: 1, - }) + try { + const [searchResult] = await agent.searchUser({ + term: term, + limit: 1, + }) - const { isSimilar: isUserFound, type } = isSimilarUser({ - accountName: twAccountName, - accountNameRemoveUnderscore: twAccountNameRemoveUnderscore, - displayName: twDisplayName, - }, searchResult) + const { isSimilar: isUserFound, type } = isSimilarUser({ + accountName: twAccountName, + accountNameRemoveUnderscore: twAccountNameRemoveUnderscore, + displayName: twDisplayName, + }, searchResult) - if (isUserFound) { - targetAccount = searchResult - matchType = type - break; // Stop searching when a user is found + if (isUserFound) { + targetAccount = searchResult + matchType = type + break; // Stop searching when a user is found + } + } catch (e) { + console.error(e) } } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 4c87ac5..2a89352 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -3,3 +3,7 @@ export const debugLog = (message: string) => { console.log(`🔷 [Sky Follower Bridge] ${message}`) } } + +export const isOneSymbol = (str: string) => { + return /^[^\w\s]$/.test(str); +}