scanner api is no longer accessible to users

This commit is contained in:
IrosTheBeggar 2021-05-29 11:48:18 -04:00
parent e10440dcee
commit f8ce86f8cd
3 changed files with 22 additions and 11 deletions

View File

@ -48,6 +48,7 @@ exports.setup = (mstream) => {
const decoded = jwt.verify(token, config.program.secret);
if (decoded.scan === true && req.path.startsWith('/api/v1/scanner/')) {
req.scanApproved = true;
return next();
}

View File

@ -3,6 +3,11 @@ const db = require('../db/manager');
const config = require('../state/config');
exports.setup = (mstream) => {
mstream.all('/api/v1/scanner/*', (req, res, next) => {
if (req.scanApproved !== true) { return res.status(403).json({ error: 'Access Denied' }); }
next();
});
mstream.post('/api/v1/scanner/get-file', async (req, res) => {
try {
const lol = { '$and': [

View File

@ -65,18 +65,23 @@ async function insertEntries(song) {
run();
async function run() {
await recursiveScan(loadJson.directory);
try {
await recursiveScan(loadJson.directory);
await axios({
method: 'POST',
url: `http://localhost:${loadJson.port}/api/v1/scanner/finish-scan`,
headers: { 'accept': 'application/json', 'x-access-token': loadJson.token },
responseType: 'json',
data: {
vpath: loadJson.vpath,
scanId: loadJson.scanId
}
});
await axios({
method: 'POST',
url: `http://localhost:${loadJson.port}/api/v1/scanner/finish-scan`,
headers: { 'accept': 'application/json', 'x-access-token': loadJson.token },
responseType: 'json',
data: {
vpath: loadJson.vpath,
scanId: loadJson.scanId
}
});
}catch (err) {
console.error('Scan Failed');
console.error(err.stack)
}
}
async function recursiveScan(dir) {