From cb15352e819182d82bf5c5b393b3a3a39e5949e9 Mon Sep 17 00:00:00 2001 From: b1ek Date: Thu, 9 Mar 2023 23:26:00 +1000 Subject: [PATCH] add services page --- middleware/template.js | 6 +++- models/permission.js | 75 +++--------------------------------------- public/static/main.css | 15 +++++++++ routes/pages.js | 10 ++++++ view/layout/main.pug | 4 ++- view/page/services.pug | 44 +++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 routes/pages.js create mode 100644 view/page/services.pug diff --git a/middleware/template.js b/middleware/template.js index fd0e47c..c0a4746 100644 --- a/middleware/template.js +++ b/middleware/template.js @@ -7,8 +7,12 @@ module.exports = (req, res, next) => { res.template = async (file, data) => { + + let t_data = {}; + if (data) t_data = {...data}; + res.send(await Helpers.ViewLoader.load(file, { - ...data, + ...t_data, current_route: req.originalUrl, req, res, diff --git a/models/permission.js b/models/permission.js index e69146e..c9fe2d1 100644 --- a/models/permission.js +++ b/models/permission.js @@ -1,72 +1,9 @@ const { Model, DataTypes } = require('sequelize'); const { sequelize } = require('.'); -/** @type {{data: Permission[], updated: number, expired: function}} */ -let cached = { - data: undefined, - updated: 0, - expired: () => { - return (Date.now() - updated) >= 1000 - } -} - class Permission extends Model { - static async cache() { - if (!cached.expired()) return; - - cached.data = await Permission.findAll(); - cached.updated = Date.now(); - } - - /** - * Get value from cache - * @param {number} user - * @param {string} permission - * @returns {Permission?} - */ - static async findFromCache(user, permission) { - await this.cache(); - for (const perm of cached.data) { - if (perm.user == userid && perm.permission == permission) - return perm; - } - return null; - } - - /** - * Get a permission for user - * @param {number} user - * @param {string} permission - * @returns {boolean} - */ - static async forUser(user, permission) { - await this.cache(); - const data = await this.findFromCache(user, permission); - if (!data) return false; - return data.value != 0; - } - - /** - * Set a permission for user - * @param {number} user - * @param {string} permission - * @param {number} value - * @returns {Permission} - */ - static async set(user, permission, value) { - const existing = await Permission.findOne({where: {user, permission}}); - - let perm; - - if (!existing) perm = await Permission.create({user, permission, value}); - else perm = await Permission.update({user, permission, value}, {where: {user, permission}}); - await this.cache(); - - return perm; - } - - static async userAllowed(user, permission) { - return this.forUser(user, permission); + static async getAllForUser(user) { + return await this.findAll({where: {user}}); } } @@ -81,12 +18,8 @@ Permission.structure = { type: DataTypes.BIGINT, allowNull: false }, - permission: { - type: DataTypes.TEXT, - allowNull: false - }, - value: { - type: DataTypes.BIGINT, + perms: { + type: DataTypes.JSONB, allowNull: false } }; diff --git a/public/static/main.css b/public/static/main.css index c9d9dcf..d7ea583 100644 --- a/public/static/main.css +++ b/public/static/main.css @@ -108,4 +108,19 @@ span.flag_btn { span.au_flag { background: url(/content/au_flag.jpg); +} + +table.border_table, table.border_table tr td { + border: 1px solid #c2c4c2; + border-collapse: collapse; +} +table.border_table tr td, table.border_table tr th { + padding: 4px 10px; + border: 1px solid #c2c4c2; +} +table.border_table tr th { + border-bottom: 3px double #caccca; + padding: 2px 10px; + font-size: 90%; + text-align: center; } \ No newline at end of file diff --git a/routes/pages.js b/routes/pages.js new file mode 100644 index 0000000..4bfddf2 --- /dev/null +++ b/routes/pages.js @@ -0,0 +1,10 @@ +const handler = require('express-async-handler'); + +async function services(req, res) { + res.template('page/services.pug'); +} + + +module.exports = (router) => { + router.get('/services', handler(services)) +} \ No newline at end of file diff --git a/view/layout/main.pug b/view/layout/main.pug index dd00ad3..7b3b638 100644 --- a/view/layout/main.pug +++ b/view/layout/main.pug @@ -9,7 +9,9 @@ block root "Guestbook": "/guestbook", "Articles": "/articles", "hr_2": "hr", - "Sources": "/sources" + "Sources": "/sources", + "Services": "/services", + "Resume": "/resume" } doctype html diff --git a/view/page/services.pug b/view/page/services.pug new file mode 100644 index 0000000..8c14c17 --- /dev/null +++ b/view/page/services.pug @@ -0,0 +1,44 @@ +extends ../layout/main.pug +block root + - var title = 'Services' + include ../ui/label.pug + +block content + h2 My self-hosted services + hr + table(class='border_table' style='font-size:11pt') + tr + th Name + th Link + th Description + tr + td Excalidraw + td + a(href='https://draw.blek.codes' class='web_link') draw.blek.codes + td + | A draw board. Has real-time collaborative features. + a(href='https://excalidraw.com') Official site + tr + td Gitea + td + a(href='https://git.blek.codes' class='web_link') git.blek.codes + td + | My gitea instance. I store all my new work here, although it is mirrored to github. + tr + td blek! Bin + td + a(href='https://bin.blek.codes' class='web_link') bin.blek.codes + td + | A privacy-respecting, js-free pastebin alternative (inspired by + a(href='https://github.com/hnhx/librebin') Librebin + | ) + a(href='/project/blek_bin' class='web_link') Project page + tr + td Mailcow + td No public web gui + td + | A set of programs to run a mail service. + a(href='https://mailcow.email' class='web_link') Official site + p + a(href='http://kuma.blek.codes/status/all') + +label('Status page', '#58ac58') \ No newline at end of file