mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
scanner api is no longer accessible to users
This commit is contained in:
parent
e10440dcee
commit
f8ce86f8cd
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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': [
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user