From 400043b1be38cdd7bc39462fa6a545eea0bea03e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 Oct 2021 15:01:17 +0200 Subject: Add ability to search by URL with query params --- server/controllers/api/search/shared/index.ts | 1 + server/controllers/api/search/shared/utils.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 server/controllers/api/search/shared/index.ts create mode 100644 server/controllers/api/search/shared/utils.ts (limited to 'server/controllers/api/search/shared') diff --git a/server/controllers/api/search/shared/index.ts b/server/controllers/api/search/shared/index.ts new file mode 100644 index 000000000..9c56149ef --- /dev/null +++ b/server/controllers/api/search/shared/index.ts @@ -0,0 +1 @@ +export * from './utils' diff --git a/server/controllers/api/search/shared/utils.ts b/server/controllers/api/search/shared/utils.ts new file mode 100644 index 000000000..e02e84f31 --- /dev/null +++ b/server/controllers/api/search/shared/utils.ts @@ -0,0 +1,16 @@ +async function searchLocalUrl (url: string, finder: (url: string) => Promise) { + const data = await finder(url) + if (data) return data + + return finder(removeQueryParams(url)) +} + +export { + searchLocalUrl +} + +// --------------------------------------------------------------------------- + +function removeQueryParams (url: string) { + return url.split('?').shift() +} -- cgit v1.2.3