Added the Sheepstar API to the Archive

This commit is contained in:
2022-09-06 16:37:56 +02:00
parent d6c272cdaf
commit bb78376745
36 changed files with 5346 additions and 0 deletions

View File

@ -0,0 +1,25 @@
const GrantedPermission = require("../models/GrantedPermission");
const Session = require("../models/Session");
module.exports = function(permissionNode) {
return async function(req, res, next) {
// Set the token
let token = req.token;
if (req.tokenType === "client") token = req.clientId;
// Get permissions from client
const clientPermissions = await GrantedPermission.findAll({where: {token: token}});
// Check permission
for (let permission in clientPermissions) {
if (clientPermissions[permission].permissionNode === "*") return next();
try {
if (new RegExp(clientPermissions[permission].permissionNode).test(permissionNode)) return next();
} catch {}
}
// Return if client has no permission
res.status(403).json({message: `You need the permission '${permissionNode}' to perform this action.`});
}
}