Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Replace build-url with native functionality (#2140)

Olga Bulat0cdba2dc84db
diff --git a/frontend/package.json b/frontend/package.json
index a59e595f2..9208e4934 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -80,7 +80,6 @@
"axios": "^0.27.0",
"axios-mock-adapter": "^1.20.0",
"babel-core": "^7.0.0-bridge.0",
- "build-url": "^6.0.1",
"case": "^1.6.3",
"clipboard": "^2.0.8",
"cookie-universal-nuxt": "^2.1.5",
diff --git a/frontend/src/utils/get-additional-sources.ts b/frontend/src/utils/get-additional-sources.ts
index 080d8b599..475374ab8 100644
--- a/frontend/src/utils/get-additional-sources.ts
+++ b/frontend/src/utils/get-additional-sources.ts
@@ -1,12 +1,8 @@
-import buildUrl from "build-url"
-
import type { MediaType } from "~/constants/media"
import type { ApiQueryParams } from "~/utils/search-query-transform"
import { MODEL_3D } from "~/constants/media"
-import type { BuildUrlOptions } from "build-url"
-
/**
* Describes the query format used by the URL builder functions of additional
* sources. This includes the query string and the usage filters.
@@ -29,9 +25,10 @@ const transformSearchQuery = (
})
type SearchFunctions = {
- [k in MediaType]?: (
- search: AdditionalSearchQuery
- ) => BuildUrlOptions & { url: string }
+ [k in MediaType]?: (search: AdditionalSearchQuery) => {
+ queryParams: Record<string, string | string[]>
+ url: string
+ }
}
/**
@@ -223,7 +220,6 @@ const additionalSourceBuilders: AdditionalSourceBuilder[] = [
q: search.q,
licenses: licenseCodes,
},
- disableCSV: true,
}
},
},
@@ -263,15 +259,29 @@ export const getAdditionalSourceBuilders = (
export const getAdditionalSources = (
mediaType: MediaType,
query: ApiQueryParams
-) =>
+): AdditionalSource[] =>
getAdditionalSourceBuilders(mediaType).map((source) => {
const urlFunc = source[mediaType]
-
- if (!urlFunc) return undefined // type-guard, never occurs
+ // type-guard, never occurs
+ if (!urlFunc) {
+ throw new Error(
+ `Invalid media type ${mediaType} for additional source ${source.name}`
+ )
+ }
const urlInfo = urlFunc(transformSearchQuery(query))
+ const sourceUrl = new URL(urlInfo.url)
+ for (const [key, value] of Object.entries(urlInfo.queryParams)) {
+ if (Array.isArray(value)) {
+ for (const v of value) {
+ sourceUrl.searchParams.append(key, v)
+ }
+ } else {
+ sourceUrl.searchParams.set(key, value)
+ }
+ }
return {
- url: buildUrl(urlInfo.url, urlInfo),
+ url: sourceUrl.href,
name: source.name,
}
- }) as AdditionalSource[]
+ })
diff --git a/package.json b/package.json
index 10896ac9d..97baf2c0d 100644
--- a/package.json
+++ b/package.json
@@ -27,8 +27,7 @@
"consola"
],
"allowedVersions": {
- "babel-core": "7.0.0-bridge.0",
- "postcss": "5.2.18"
+ "babel-core": "7.0.0-bridge.0"
}
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 54bb132e6..91bd070d6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -73,7 +73,6 @@ importers:
babel-core: ^7.0.0-bridge.0
babel-jest: ^26.6.3
babel-loader: 8.2.5
- build-url: ^6.0.1
case: ^1.6.3
chokidar: ^3.5.3
clipboard: ^2.0.8
@@ -152,7 +151,6 @@ importers:
axios: 0.27.2
axios-mock-adapter: [email protected]
babel-core: 7.0.0-bridge.0_@[email protected]
- build-url: 6.0.1
case: 1.6.3
clipboard: 2.0.8
cookie-universal-nuxt: 2.1.5
@@ -8343,11 +8341,6 @@ packages:
ieee754: 1.2.1
isarray: 1.0.0
- /build-url/6.0.1:
- resolution: {integrity: sha512-FEmyP+3hCVoBBxGZEfC8WCTvqASZb+QOvTznddKCBgdxZFqTww1+7vtZP0TUIL0/8sup0m0QpKaOaj/V4Mol0w==}
- deprecated: This package is no longer maintained
- dev: false
-
/builtin-modules/3.2.0:
resolution: {integrity: sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==}
engines: {node: '>=6'}