« get me outta code hell

web-routes: basic implementation - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/web-routes.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-26 21:13:32 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-01 20:00:45 -0300
commitcf47bb13a9a6713d94034e41d63e756d1f02a0f2 (patch)
tree098676b4d5fee194c7152cda7b5108247c2f0727 /src/web-routes.js
parentc3d3d65145105c15b1cfa69c927067de48a37862 (diff)
web-routes: basic implementation
Diffstat (limited to 'src/web-routes.js')
-rw-r--r--src/web-routes.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/web-routes.js b/src/web-routes.js
new file mode 100644
index 00000000..1d010b66
--- /dev/null
+++ b/src/web-routes.js
@@ -0,0 +1,61 @@
+import {readdir} from 'node:fs/promises';
+import * as path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+
+const codeSrcPath = __dirname;
+const codeRootPath = path.resolve(codeSrcPath, '..');
+
+function getNodeDependencyRootPath(dependencyName) {
+  const packageJSON =
+    import.meta.resolve(dependencyName + '/package.json');
+
+  return path.dirname(fileURLToPath(packageJSON));
+}
+
+export const stationaryCodeRoutes = [
+  {
+    from: path.join(codeSrcPath, 'static'),
+    to: '/static',
+  },
+
+  {
+    from: path.join(codeSrcPath, 'util'),
+    to: '/util',
+  },
+];
+
+export const dependencyRoutes = [];
+
+export const allStaticWebRoutes = [
+  ...stationaryCodeRoutes,
+  ...dependencyRoutes,
+];
+
+export async function identifyDynamicWebRoutes({
+  mediaPath,
+  mediaCachePath,
+}) {
+  const routeFunctions = [
+    () => Promise.resolve([
+      {from: path.resolve(mediaPath), to: '/media'},
+      {from: path.resolve(mediaCachePath), to: '/thumb'},
+    ]),
+  ];
+
+  const routeCheckPromises =
+    routeFunctions.map(fn => fn());
+
+  const routeCheckResults =
+    await Promise.all(routeCheckPromises);
+
+  return routeCheckResults.flat();
+}
+
+export async function identifyAllWebRoutes(opts) {
+  return [
+    ...allStaticWebRoutes,
+    ...await identifyDynamicWebRoutes(opts),
+  ];
+}