replaced github endpoints with jsdelivr
This commit is contained in:
parent
81633dd711
commit
a3ec616fd4
1 changed files with 22 additions and 16 deletions
|
@ -17,8 +17,8 @@ import redirects from "~data/redirects.json";
|
||||||
|
|
||||||
const cache = new Map();
|
const cache = new Map();
|
||||||
const filePathBlockchain = "/contrib/devtools/generated/api_v1.json";
|
const filePathBlockchain = "/contrib/devtools/generated/api_v1.json";
|
||||||
const filePathSdk = "/docs/api.json";
|
const filePathSdk = "docs/api.json";
|
||||||
const rawGitHubBase = "https://raw.githubusercontent.com/lbryio/";
|
const rawGitHubBase = "https://cdn.jsdelivr.net/gh/lbryfoundation/";
|
||||||
|
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
auth: `token ${process.env.GITHUB_OAUTH_TOKEN}`
|
auth: `token ${process.env.GITHUB_OAUTH_TOKEN}`
|
||||||
|
@ -92,6 +92,7 @@ export default async(state) => {
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.log(error);
|
||||||
const redirectUrl = redirects[state.href];
|
const redirectUrl = redirects[state.href];
|
||||||
|
|
||||||
return asyncHtml`
|
return asyncHtml`
|
||||||
|
@ -238,10 +239,12 @@ function createSdkSidebar(apiDetails) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTags(repositoryName) {
|
async function getTags(repositoryName) {
|
||||||
const { data } = await octokit.repos.listTags({
|
const {versions: data} = await (await fetch(`https://data.jsdelivr.com/v1/packages/gh/lbryfoundation/${repositoryName}`)).json();
|
||||||
owner: "lbryio",
|
|
||||||
repo: repositoryName
|
// const { data } = await octokit.repos.listTags({
|
||||||
});
|
// owner: "lbryio",
|
||||||
|
// repo: repositoryName
|
||||||
|
// });
|
||||||
|
|
||||||
const tags = ["master"];
|
const tags = ["master"];
|
||||||
|
|
||||||
|
@ -254,19 +257,20 @@ async function getTags(repositoryName) {
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case repositoryName === "lbry-sdk":
|
case repositoryName === "lbry-sdk":
|
||||||
data.forEach(tag => {
|
data.forEach(tag => {
|
||||||
if (tag.name >= "v0.52.0") tags.push(tag.name);
|
if (tag.version >= "v0.52.0") tags.push(tag.version);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case repositoryName === "lbrycrd":
|
case repositoryName === "lbrycrd":
|
||||||
data.forEach(tag => {
|
data.forEach(tag => {
|
||||||
if (
|
if (
|
||||||
tag.name >= "v0.17.1.0" &&
|
tag.version >= "v0.17.1.0" &&
|
||||||
tag.name !== "v0.3.16" &&
|
tag.version !== "v0.3.16" &&
|
||||||
tag.name !== "v0.3.15" &&
|
tag.version !== "v0.3.15" &&
|
||||||
tag.name !== "v0.3-osx" &&
|
tag.version !== "v0.3-osx" &&
|
||||||
tag.name !== "v0.2-alpha"
|
tag.version !== "v0.2-alpha"
|
||||||
) tags.push(tag.name);
|
)
|
||||||
|
tags.push(tag.version);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -278,7 +282,7 @@ async function getTags(repositoryName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseApiFile({ repo, tag }) {
|
async function parseApiFile({ repo, tag }) {
|
||||||
let apiFileLink = `${rawGitHubBase}${repo}/${tag}`;
|
let apiFileLink = `${rawGitHubBase}${repo}@${tag}/`;
|
||||||
|
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case (repo === "lbrycrd"):
|
case (repo === "lbrycrd"):
|
||||||
|
@ -293,10 +297,12 @@ async function parseApiFile({ repo, tag }) {
|
||||||
return Promise.reject(new Error("Failed to fetch API docs"));
|
return Promise.reject(new Error("Failed to fetch API docs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await got(apiFileLink, { cache, json: true });
|
// const response = await got(apiFileLink, { cache, json: true });
|
||||||
|
console.log(apiFileLink);
|
||||||
|
const response = await fetch(apiFileLink);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response.body;
|
return response.json();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return "Issue loading API documentation";
|
return "Issue loading API documentation";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue