//native
type Gitbook = {
token: string;
};
/**
* Resolve a URL to an embed
*
*/
export async function main(auth: Gitbook, url: string | undefined) {
const url_ = new URL(`https://api.gitbook.com/v1/urls/embed`);
for (const [k, v] of [["url", url]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url_.searchParams.append(k, v);
}
}
const response = await fetch(url_, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago