@sealos/agendash
Version:
A fork of dashboard for Agenda.js with Pagination and Search capabilities
103 lines • 3.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const express_1 = __importDefault(require("express"));
const body_parser_1 = __importDefault(require("body-parser"));
const agendash_1 = require("./controllers/agendash");
const CSP = {
"default-src": [
"'self'",
],
"script-src": [
"https://code.jquery.com",
"https://cdn.jsdelivr.net",
"https://cdnjs.cloudflare.com",
"https://stackpath.bootstrapcdn.com",
"'unsafe-inline'",
"'unsafe-eval'",
"'self'",
],
"style-src": [
"https://cdn.jsdelivr.net",
"https://stackpath.bootstrapcdn.com",
"https://fonts.googleapis.com",
"https://unpkg.com",
"'self'",
],
"font-src": [
"https://fonts.gstatic.com",
],
};
const csp = Object.entries(CSP)
.map(([type, values]) => `${type} ${values.join(" ")}`)
.join("; ");
function expressMiddleware(agendash) {
const expressApp = (0, express_1.default)();
expressApp.use(body_parser_1.default.json());
expressApp.use(body_parser_1.default.urlencoded({ extended: false }));
expressApp.use((req, res, next) => {
res.header('Content-Security-Policy', csp);
next();
});
expressApp.use('/', express_1.default.static(path_1.default.join(__dirname, '../public')));
expressApp.get('/api', async (request, response) => {
try {
const { job, state, skip, limit, q, property, isObjectId, } = request.query;
const apiResponse = await agendash.api(job, state, {
query: q,
property,
isObjectId,
skip,
limit,
});
response.json(apiResponse);
}
catch (error) {
response.status(400).json(error);
}
});
expressApp.post('/api/jobs/requeue', async (request, response) => {
try {
const newJobs = await agendash.requeueJobs(request.body.jobIds);
response.send(newJobs);
}
catch (error) {
response.status(404).json(error);
}
});
expressApp.post('/api/jobs/delete', async (request, response) => {
try {
const body = request.body;
const deleted = await agendash.deleteJobs(body.jobIds);
if (deleted) {
response.json({ deleted: true });
}
else {
response.json({ message: 'Jobs not deleted' });
}
}
catch (error) {
response.status(404).json(error);
}
});
expressApp.post('/api/jobs/create', async (request, response) => {
try {
const body = request.body;
await agendash.createJob(body.jobName, body.jobSchedule, body.jobRepeatEvery, body.jobData);
response.json({ created: true });
}
catch (error) {
response.status(400).json(error);
}
});
return expressApp;
}
function Agendash(agenda) {
const agendash = new agendash_1.AgendashController(agenda);
return expressMiddleware(agendash);
}
exports.default = Agendash;
//# sourceMappingURL=app.js.map