mirror of
https://github.com/upstash/context7.git
synced 2025-12-08 04:52:25 +00:00
refactor(api): make param handling more terse
This commit is contained in:
parent
30ab52ae79
commit
a83042c6bc
@ -46,20 +46,10 @@ export async function fetchLibraryDocumentation(
|
|||||||
basePath = path;
|
basePath = path;
|
||||||
folders = foldersParam;
|
folders = foldersParam;
|
||||||
}
|
}
|
||||||
let contextURL = `${CONTEXT7_BASE_URL}/${basePath}/llms.txt`;
|
const contextURL = new URL(`${CONTEXT7_BASE_URL}/${basePath}/llms.txt`);
|
||||||
const params = [];
|
if (folders) contextURL.set('folders', folders)
|
||||||
if (folders) {
|
if (tokens) contextURL.set('tokens', tokens)
|
||||||
params.push(`folders=${encodeURIComponent(folders)}`);
|
if (topic) contextURL.set('topic', topic)
|
||||||
}
|
|
||||||
if (tokens) {
|
|
||||||
params.push(`tokens=${tokens}`);
|
|
||||||
}
|
|
||||||
if (topic) {
|
|
||||||
params.push(`topic=${encodeURIComponent(topic)}`);
|
|
||||||
}
|
|
||||||
if (params.length > 0) {
|
|
||||||
contextURL += `?${params.join("&")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(contextURL);
|
const response = await fetch(contextURL);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user