summaryrefslogtreecommitdiff
path: root/routes/search.js
blob: 6732c52fda2242a48a0afcc3d43de9873496a594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"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});
};

module.exports = search;