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;
|
||||
folders = foldersParam;
|
||||
}
|
||||
let contextURL = `${CONTEXT7_BASE_URL}/${basePath}/llms.txt`;
|
||||
const params = [];
|
||||
if (folders) {
|
||||
params.push(`folders=${encodeURIComponent(folders)}`);
|
||||
}
|
||||
if (tokens) {
|
||||
params.push(`tokens=${tokens}`);
|
||||
}
|
||||
if (topic) {
|
||||
params.push(`topic=${encodeURIComponent(topic)}`);
|
||||
}
|
||||
if (params.length > 0) {
|
||||
contextURL += `?${params.join("&")}`;
|
||||
}
|
||||
const contextURL = new URL(`${CONTEXT7_BASE_URL}/${basePath}/llms.txt`);
|
||||
if (folders) contextURL.set('folders', folders)
|
||||
if (tokens) contextURL.set('tokens', tokens)
|
||||
if (topic) contextURL.set('topic', topic)
|
||||
|
||||
const response = await fetch(contextURL);
|
||||
if (!response.ok) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user