summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/search.js17
-rw-r--r--routes/settings.js4
-rw-r--r--server/js/config.js3
3 files changed, 21 insertions, 3 deletions
diff --git a/routes/search.js b/routes/search.js
index e7a1b41..6732c52 100644
--- a/routes/search.js
+++ b/routes/search.js
@@ -1,12 +1,29 @@
"use strict";
const apibay = require('../server/js/apibay');
+const config = require('../server/js/config');
const template = require('../server/js/template');
async function search(req, res)
{
let query = req.body.search;
let results = await apibay.hit(query);
+
+ // Filter NSFW Content
+ if (!config.loadedConfig.settings.nsfw_content)
+ {
+ results = Array.prototype.filter.call(results, result => {
+
+ let category = parseInt(result.category);
+
+ if ( !(category > 500 && category < 600) )
+ {
+ return result;
+ }
+
+ });
+ }
+
res.render('result', {query: query, results: results, functions: template, showSearchBar: true});
};
diff --git a/routes/settings.js b/routes/settings.js
index 59b9f80..6f3baf6 100644
--- a/routes/settings.js
+++ b/routes/settings.js
@@ -12,7 +12,7 @@ function save(req, res)
let newConfig = {
'settings': {
'nsfw_content': ((req.body.nsfw === "on") ? true : false),
- 'port': ((!isNaN(parseInt(req.body.port))) ? parseInt(req.body.port) : 3000),
+ 'port': ((!isNaN(parseInt(req.body.port))) ? parseInt(req.body.port) : undefined),
'tor': {
'host': ((req.body.torHost) ? req.body.torHost : undefined),
'port': ((!isNaN(parseInt(req.body.torPort))) ? parseInt(req.body.torPort) : undefined)
@@ -23,7 +23,7 @@ function save(req, res)
config.createConfig(newConfig);
config.loadConfig();
- res.render('settings', {showSearchBar: true, config: config.loadedConfig});
+ res.redirect('/');
};
module.exports = {settings, save};
diff --git a/server/js/config.js b/server/js/config.js
index f688bb7..a184515 100644
--- a/server/js/config.js
+++ b/server/js/config.js
@@ -6,6 +6,7 @@ const path = require('path');
const { ensureFolder, envPaths } = require('./paths');
// Handling Variables
+const indentation = '\t';
const configFolder = ensureFolder(path.join(envPaths.CONFIG, 'sneedbay'));
const defaultConfigPath = path.join(configFolder, 'config.json');
const defaultConfig = {
@@ -28,7 +29,7 @@ function createConfig(customConfig, configPath)
try
{
- fs.writeFileSync(path, JSON.stringify(config), 'utf-8');
+ fs.writeFileSync(path, JSON.stringify(config, null, indentation), 'utf-8');
}
catch (err)