Skip to content

Commit

Permalink
chore: initial profiles listing support
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Aug 6, 2024
1 parent 5d65f5b commit 35fff8c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// requires the multiple libraries
const fs = require("fs/promises");
const express = require("express");
const session = require("express-session");
const path = require("path");
Expand Down Expand Up @@ -209,6 +210,22 @@ app.get("/config", (req, res, next) => {
res.json(req.session.config || {});
});

app.get("/profiles", async (req, res, next) => {
const directoryPath = path.join(__dirname, "static", "profiles");
const files = await fs.readdir(directoryPath);
const profiles = {};
for (const file of files) {
const filePath = path.join(directoryPath, file);
if (path.extname(file) === ".json") {
const fileContent = await fs.readFile(filePath, "utf8");
const jsonObject = JSON.parse(fileContent);
const name = path.basename(file, ".json");
profiles[name] = jsonObject;
}
}
res.json(profiles);
});

app.get("/info", (req, res, next) => {
res.json({
name: info.name,
Expand Down

0 comments on commit 35fff8c

Please sign in to comment.