From e40a0b98e4b1ac1c897b0b30f9b9408e473791e0 Mon Sep 17 00:00:00 2001 From: nomad Date: Sat, 8 Jul 2023 16:41:52 +0800 Subject: [PATCH] fix(frontend): search user with trailing space (#11184) * fix(frontend): search user with trailing space * fix(backend): search user with trailing space * Update search.ts --------- Co-authored-by: syuilo --- packages/backend/src/server/api/endpoints/users/search.ts | 1 + packages/backend/src/server/api/endpoints/users/show.ts | 1 + packages/frontend/src/pages/search.user.vue | 2 +- packages/frontend/src/scripts/lookup.ts | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/users/search.ts b/packages/backend/src/server/api/endpoints/users/search.ts index 177441bc78..1180de3611 100644 --- a/packages/backend/src/server/api/endpoints/users/search.ts +++ b/packages/backend/src/server/api/endpoints/users/search.ts @@ -52,6 +52,7 @@ export default class extends Endpoint { super(meta, paramDef, async (ps, me) => { const activeThreshold = new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)); // 30日 + ps.query = ps.query.trim(); const isUsername = ps.query.startsWith('@'); let users: User[] = []; diff --git a/packages/backend/src/server/api/endpoints/users/show.ts b/packages/backend/src/server/api/endpoints/users/show.ts index ba432c273b..8e25af64fe 100644 --- a/packages/backend/src/server/api/endpoints/users/show.ts +++ b/packages/backend/src/server/api/endpoints/users/show.ts @@ -91,6 +91,7 @@ export default class extends Endpoint { let user; const isModerator = await this.roleService.isModerator(me); + ps.username = ps.username?.trim(); if (ps.userIds) { if (ps.userIds.length === 0) { diff --git a/packages/frontend/src/pages/search.user.vue b/packages/frontend/src/pages/search.user.vue index bd1389ffef..8e4a4a78c5 100644 --- a/packages/frontend/src/pages/search.user.vue +++ b/packages/frontend/src/pages/search.user.vue @@ -67,7 +67,7 @@ async function search() { endpoint: 'users/search', limit: 10, params: { - query: searchQuery, + query: query, origin: searchOrigin, }, }; diff --git a/packages/frontend/src/scripts/lookup.ts b/packages/frontend/src/scripts/lookup.ts index 0b594e3412..a55868368e 100644 --- a/packages/frontend/src/scripts/lookup.ts +++ b/packages/frontend/src/scripts/lookup.ts @@ -6,9 +6,10 @@ import { Router } from '@/nirax'; export async function lookup(router?: Router) { const _router = router ?? mainRouter; - const { canceled, result: query } = await os.inputText({ + const { canceled, result: temp } = await os.inputText({ title: i18n.ts.lookup, }); + const query = temp ? temp.trim() : ''; if (canceled) return; if (query.startsWith('@') && !query.includes(' ')) {