浏览代码

UI skeletton

isundil 2 年之前
父节点
当前提交
4655c2eb33

+ 3 - 1
main.js

@@ -20,7 +20,9 @@ function App() {
 App.prototype.init = async function() {
     [
         "./router/mdi.js",
-        "./router/api.js"
+        "./router/api.js",
+
+        "./router/index.js"
     ].forEach(i => require(i).register(this));
     await this.databaseHelper.init();
 }

+ 1 - 1
model/mediaService.js

@@ -23,7 +23,7 @@ MediaStruct.prototype.pushTag = function(tag) {
 
 MediaStruct.prototype.HaveAccess = function(accessList) {
     // FIXME
-    return false;
+    return true;
 }
 
 function reduceReqToMediaStruct(acc, i) {

+ 3 - 1
package.json

@@ -13,6 +13,7 @@
   "author": "isundil",
   "license": "ISC",
   "dependencies": {
+    "@mdi/font": "^7.3.67",
     "crypto": "^1.0.1",
     "geokit": "^1.1.0",
     "imagemagick": "^0.1.3",
@@ -20,6 +21,7 @@
     "ldapjs": "^3.0.4",
     "mime-types": "^2.1.35",
     "node-simple-router": "^0.10.2",
-    "sqlite3": "^5.1.6"
+    "sqlite3": "^5.1.6",
+    "whiskers": "^0.4.0"
   }
 }

+ 12 - 0
router/index.js

@@ -0,0 +1,12 @@
+
+const whiskers = require('whiskers');
+
+module.exports = { register: app => {
+    app.router.get("/", (req, res) => {
+        let context = app.routerUtils.commonRenderInfos();
+        context.page_title += " - Dashboard";
+        context.sources = [];
+        res.end(whiskers.render(require('../templates/index.js'), context));
+    });
+}};
+

+ 26 - 26
src/routerUtils.js

@@ -115,25 +115,36 @@ RouterUtils.prototype.onPageNotFound = function(res) {
 
 RouterUtils.prototype.staticServe = async function(res, filePath) {
     return new Promise((ok, ko) => {
-        const stream = fs.createReadStream(filePath);
-        const fileSize = fs.statSync(filePath)?.size || undefined;
-        if (!stream || !fileSize) {
-            console.error("RouterUtils::staticGet", filePath, err);
-            this.httpResponse(res, 500, "Internal Server Error");
-            return ko(err);
+        try {
+            const stream = fs.createReadStream(filePath);
+            let onError = false;
+            stream.once('error', err => {
+                ko(err);
+                onError = true;
+            });
+            const fileSize = fs.statSync(filePath)?.size || undefined;
+            if (!stream || !fileSize || onError) {
+                console.error("RouterUtils::staticGet", filePath, err);
+                this.httpResponse(res, 500, "Internal Server Error");
+                return ko(err);
+            }
+            res.writeHead(200, {
+                "Content-Type": mime.contentType(path.basename(filePath)),
+                "Content-Length": fileSize
+            });
+            stream.pipe(res);
+            stream.once('end', () => ok());
+        } catch (err) {
+            ko(err);
         }
-        res.writeHead(200, {
-            "Content-Type": mime.contentType(path.basename(filePath)),
-            "Content-Length": fileSize
-        });
-        stream.pipe(res);
-        stream.once('end', () => ok());
     });
 }
 
 RouterUtils.prototype.staticGet = function(app, url, staticResources) {
     app.router.get(url, (req, res) => {
-        app.routerUtils.staticServe(res, staticResources);
+        app.routerUtils.staticServe(res, staticResources).catch(err => {
+            app.routerUtils.onPageNotFound(res);
+        });
     });
 }
 
@@ -153,20 +164,9 @@ RouterUtils.prototype.decodeUrlComponent = function(input) {
     return RouterUtils.decodeUrlComponent(input);
 }
 
-RouterUtils.prototype.commonRenderInfos = function(endpointName) {
-    let context = {
-        page_title: CONFIG.sitename,
-        endpoints: [],
-        currentEndpoint: endpointName
+RouterUtils.prototype.commonRenderInfos = function() {
+    return {
     };
-    for (let endpoint in CONFIG.endpoints)
-        context.endpoints.push({
-            name: endpoint,
-            address: '/dashboard/'+this.encodeUrlComponent(endpoint),
-            selected: endpoint === endpointName,
-            icon: CONFIG.endpoints[endpoint].icon
-        });
-    return context;
 }
 
 module.exports = { RouterUtils: RouterUtils, encodeUrlComponent: RouterUtils.encodeUrlComponent, decodeUrlComponent: RouterUtils.decodeUrlComponent };

+ 0 - 0
static/public/css/style.css


+ 0 - 0
static/public/js/common.js


文件差异内容过多而无法显示
+ 1 - 0
static/public/js/jquery-3.6.1.min.js


+ 6 - 0
templates/footer.js

@@ -0,0 +1,6 @@
+
+module.exports = `
+<script src="/public/js/jquery-3.6.1.min.js"></script>
+<script src="/public/js/common.js"></script>
+</body></html>`;
+

+ 9 - 0
templates/header.js

@@ -0,0 +1,9 @@
+
+module.exports = `
+<!DOCTYPE html>
+<html>
+<head>
+<link type="text/css" rel="stylesheet" href="/public/mdi/materialdesignicons.min.css"/>
+<link type="text/css" rel="stylesheet" href="/public/css/style.css"/>
+</head>
+`;

+ 3 - 0
templates/index.js

@@ -0,0 +1,3 @@
+
+module.exports = require('./header.js') +require('./menu.js') +``+require('./footer.js');
+

+ 7 - 0
templates/menu.js

@@ -0,0 +1,7 @@
+
+module.exports = `
+<body>
+<menu>
+</menu>
+`;
+

部分文件因为文件数量过多而无法显示