Skip to content

Commit

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

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

async function fetchDataOneSource(req, res, next, url) {
if (isEmptyFile(req.params[0])) {
if (isAFile(req.params[0])) {
const reqTarget = `${url}/${req.params[0]}`;
const asset = await fetch(reqTarget);
if (asset.ok) {
Expand All @@ -73,7 +67,7 @@ async function fetchDataFromGithub(
try {
if (await fetchDataOneSource(req, res, next, baseUrl)) return;
if (secondaryUrl) {
if (fetchDataOneSource(req, res, next, secondaryUrl)) return;
if (await fetchDataOneSource(req, res, next, secondaryUrl)) return;
}
res.status(404).send("Resource not found");
} catch (error) {
Expand Down

0 comments on commit af3e6d1

Please sign in to comment.