diff options
Diffstat (limited to 'server/controllers/api/search/shared')
-rw-r--r-- | server/controllers/api/search/shared/index.ts | 1 | ||||
-rw-r--r-- | server/controllers/api/search/shared/utils.ts | 16 |
2 files changed, 17 insertions, 0 deletions
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 @@ | |||
1 | async function searchLocalUrl <T> (url: string, finder: (url: string) => Promise<T>) { | ||
2 | const data = await finder(url) | ||
3 | if (data) return data | ||
4 | |||
5 | return finder(removeQueryParams(url)) | ||
6 | } | ||
7 | |||
8 | export { | ||
9 | searchLocalUrl | ||
10 | } | ||
11 | |||
12 | // --------------------------------------------------------------------------- | ||
13 | |||
14 | function removeQueryParams (url: string) { | ||
15 | return url.split('?').shift() | ||
16 | } | ||