Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNotSus authored Apr 12, 2024
1 parent 20e945e commit 49605f4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,28 @@ app.get("/misc/*", async (req, res, next) => {
await fetchDataFromGithub(req, res, next, baseUrl, secondaryUrl);
});

async function fetchDataFromGithub(req, res, next, baseUrl, secondaryUrl = null) {
async function fetchDataFromGithub(
req,
res,
next,
baseUrl,
secondaryUrl = null
) {
function isEmptyFile(urlString) {
return urlString.trim().split('/').pop().length === 0;
return urlString.trim().split("/").pop().length === 0;
}

function fetchDataOneSource(req, res, next, url) {
async function fetchDataOneSource(req, res, next, url) {
if (isEmptyFile(req.params[0])) {
const reqTarget = `${baseUrl}/${req.params[0]}`;
const reqTarget = `${url}/${req.params[0]}`;
const asset = await fetch(reqTarget);
if (asset.ok) {
const data = await asset.arrayBuffer();
res.end(Buffer.from(data));
return true;
}
} else {
const indexReqTarget = `${baseUrl}/${req.params[0]}/index.html`;
const indexReqTarget = `${url}/${req.params[0]}/index.html`;
const indexAsset = await fetch(indexReqTarget);
if (indexAsset.ok) {
const indexData = await indexAsset.arrayBuffer();
Expand All @@ -63,9 +69,9 @@ async function fetchDataFromGithub(req, res, next, baseUrl, secondaryUrl = null)
}
return false;
}

try {
if (fetchDataOneSource(req, res, next, baseUrl)) return;
if (await fetchDataOneSource(req, res, next, baseUrl)) return;
if (secondaryUrl) {
if (fetchDataOneSource(req, res, next, secondaryUrl)) return;
}
Expand Down

0 comments on commit 49605f4

Please sign in to comment.