From 15992970bc9d3eec402f6d85e40236e3095f0fc0 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 17 Apr 2021 22:45:12 +0200 Subject: Finished repos api endpoint, created complete repos page & removed dist dir --- api/v1.js | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'api/v1.js') diff --git a/api/v1.js b/api/v1.js index 6b96e94..75509ad 100644 --- a/api/v1.js +++ b/api/v1.js @@ -8,40 +8,20 @@ const base_dir="/home/hampus/Projects/" router.get("/repos", async function(req, res) { - fs.readdir(base_dir, (err, files) => + fs.readdir(base_dir, async (err, repo_dirs) => { if(err) { throw err; } + repo_dirs = repo_dirs.filter(repo => repo.endsWith(".git")); - var repos = {}; + console.log("Repo dirs: " + repo_dirs); - files = files.filter(repo => repo.endsWith(".git")); + const repos = await git.getBasicRepoInfo(base_dir, repo_dirs); - let getRepoInfo = new Promise((resolve) => - { - files.forEach((repo, index, arr) => - { - fs.readFile(`${base_dir}/${repo}/description`, (err, content) => - { - let desc = ""; - - if(!err) { - desc = content.toString(); - } + console.log("I v1.js\n" + JSON.stringify(repos) + "\n"); - repos[repo.slice(0, -4)] = { "description": desc }; - - if(index === arr.length -1) resolve(); - }) - }); - }); - - getRepoInfo.then(() => - { - console.log(`Sist: ${JSON.stringify(repos)}`); - res.json({ "data": repos }); - }) + res.json({ "data": repos }); }); }); -- cgit v1.2.3-18-g5258