summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Marçalo <raroma09@gmail.com>2022-10-28 00:40:47 +0100
committerRafael Marçalo <raroma09@gmail.com>2022-10-28 00:40:47 +0100
commit48591e37a58d5349214e0bfee9f76e201d45e7bf (patch)
tree86f25c6bda760ed6354b3df77afe24017bd1caba
parent2f9c4d5f287c40125703c98e49ab0658a847d99b (diff)
Started working on settings menu
-rw-r--r--app.js12
-rw-r--r--routes/settings.js8
-rw-r--r--server/js/config.js28
-rw-r--r--server/js/paths.js37
-rw-r--r--views/partials/top/navbar.ejs6
-rw-r--r--views/settings.ejs5
6 files changed, 95 insertions, 1 deletions
diff --git a/app.js b/app.js
index da2a3b7..d87b6e0 100644
--- a/app.js
+++ b/app.js
@@ -4,12 +4,20 @@
const bodyParser = require('body-parser');
const express = require('express');
const path = require('path');
+
+// handling variables
const app = express();
+const { ensureFolder, envPaths } = require('./server/js/paths');
+const loadConfig = require('./server/js/config').loadConfig;
+const configFolder = ensureFolder(path.join(envPaths.CONFIG, 'sneedbay'));
+const configPath = path.join(configFolder, 'config.json');
const PORT = module.exports.PORT = process.env.PORT || 3000;
+var config = require('./server/js/config').config;
-// set the public folder to public acess and added a body parser
+// loading configurations
app.use(express.static(path.join(__dirname, '/public')));
app.use(bodyParser.urlencoded({extended: true}));
+config = loadConfig(configPath);
// set the view engine to ejs
app.set('view engine', 'ejs');
@@ -20,10 +28,12 @@ const home = require("./routes/home");
const info = require("./routes/info");
const search = require("./routes/search");
const visit = require("./routes/visit");
+const settings = require("./routes/settings");
app.get('/', home);
app.get('/info', info);
app.get('/visit', visit);
+app.get('/settings', settings);
app.post('/search', search);
// app start
diff --git a/routes/settings.js b/routes/settings.js
new file mode 100644
index 0000000..658c0f2
--- /dev/null
+++ b/routes/settings.js
@@ -0,0 +1,8 @@
+"use strict";
+
+function settings(req, res)
+{
+ res.render('settings', {showSearchBar: true});
+};
+
+module.exports = settings;
diff --git a/server/js/config.js b/server/js/config.js
new file mode 100644
index 0000000..077f928
--- /dev/null
+++ b/server/js/config.js
@@ -0,0 +1,28 @@
+"use strict";
+
+const fs = require('fs');
+
+const defaultConfig = {
+ 'settings': {
+ 'nsfw_content': false
+ }
+};
+var config = {};
+
+function createConfig(configPath, data)
+{
+ fs.writeFileSync(configPath, JSON.stringify(data), 'utf-8');
+}
+
+function loadConfig(configPath)
+{
+ if ( !fs.existsSync(configPath) )
+ {
+ createConfig(configPath, defaultConfig);
+ }
+
+ return JSON.parse(fs.readFileSync(configPath));
+}
+
+
+module.exports = {loadConfig, config}; \ No newline at end of file
diff --git a/server/js/paths.js b/server/js/paths.js
new file mode 100644
index 0000000..ee10807
--- /dev/null
+++ b/server/js/paths.js
@@ -0,0 +1,37 @@
+"use strict";
+
+const fs = require('fs');
+const path = require('path');
+const os = require('os');
+
+function ensureFolder(folder)
+{
+ if (!fs.existsSync(folder))
+ {
+ fs.mkdirSync(folder, { recursive: true });
+ }
+ return folder;
+}
+
+const envPaths = {
+ 'linux': function () {
+ return {
+ HOME: os.homedir(),
+ DATA: process.env.XDG_DATA_HOME || ensureFolder(path.join(os.homedir(), '.local', 'share')),
+ CONFIG: process.env.XDG_CONFIG_HOME || ensureFolder(path.join(os.homedir(), '.config')),
+ CACHE: process.env.XDG_CACHE_HOME || ensureFolder(path.join(os.homedir(), '.cache'))
+ }
+ },
+
+ 'win32': function () {
+ return {
+ HOME: os.homedir(),
+ DATA: process.env.APPDATA || ensureFolder(path.join(os.homedir(), 'AppData', 'Roaming')),
+ CONFIG: process.env.APPDATA || ensureFolder(path.join(os.homedir(), 'AppData', 'Roaming')),
+ CACHE: process.env.TEMP || process.env.TMP || ensureFolder(path.join(process.env.LOCALAPPDATA, 'Temp'))
+ }
+ }
+
+} [os.platform()]();
+
+module.exports = {ensureFolder, envPaths}; \ No newline at end of file
diff --git a/views/partials/top/navbar.ejs b/views/partials/top/navbar.ejs
index 356cb0b..4059dc1 100644
--- a/views/partials/top/navbar.ejs
+++ b/views/partials/top/navbar.ejs
@@ -5,6 +5,12 @@
SNEEDBAY
</a>
<div class="align-items-center d-flex justify-content-between gap-3">
+ <a href="/settings" class="link-light">
+ <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" viewBox="0 0 16 16">
+ <path d="M7.068.727c.243-.97 1.62-.97 1.864 0l.071.286a.96.96 0 0 0 1.622.434l.205-.211c.695-.719 1.888-.03 1.613.931l-.08.284a.96.96 0 0 0 1.187 1.187l.283-.081c.96-.275 1.65.918.931 1.613l-.211.205a.96.96 0 0 0 .434 1.622l.286.071c.97.243.97 1.62 0 1.864l-.286.071a.96.96 0 0 0-.434 1.622l.211.205c.719.695.03 1.888-.931 1.613l-.284-.08a.96.96 0 0 0-1.187 1.187l.081.283c.275.96-.918 1.65-1.613.931l-.205-.211a.96.96 0 0 0-1.622.434l-.071.286c-.243.97-1.62.97-1.864 0l-.071-.286a.96.96 0 0 0-1.622-.434l-.205.211c-.695.719-1.888.03-1.613-.931l.08-.284a.96.96 0 0 0-1.186-1.187l-.284.081c-.96.275-1.65-.918-.931-1.613l.211-.205a.96.96 0 0 0-.434-1.622l-.286-.071c-.97-.243-.97-1.62 0-1.864l.286-.071a.96.96 0 0 0 .434-1.622l-.211-.205c-.719-.695-.03-1.888.931-1.613l.284.08a.96.96 0 0 0 1.187-1.186l-.081-.284c-.275-.96.918-1.65 1.613-.931l.205.211a.96.96 0 0 0 1.622-.434l.071-.286zM12.973 8.5H8.25l-2.834 3.779A4.998 4.998 0 0 0 12.973 8.5zm0-1a4.998 4.998 0 0 0-7.557-3.779l2.834 3.78h4.723zM5.048 3.967c-.03.021-.058.043-.087.065l.087-.065zm-.431.355A4.984 4.984 0 0 0 3.002 8c0 1.455.622 2.765 1.615 3.678L7.375 8 4.617 4.322zm.344 7.646.087.065-.087-.065z"/>
+ </svg>
+ </a>
+
<a href="/info" class="link-light">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
diff --git a/views/settings.ejs b/views/settings.ejs
new file mode 100644
index 0000000..6919dc4
--- /dev/null
+++ b/views/settings.ejs
@@ -0,0 +1,5 @@
+<%- include('partials/header'); %>
+
+<h1>Settings</h1>
+
+<%- include('partials/footer'); %>