feat(api): implement FileCheckerAPI class with routes for file analysis
This commit is contained in:
parent
74fb118aa4
commit
87fdb0688e
2 changed files with 79 additions and 13 deletions
41
scripts/API/main.js
Normal file
41
scripts/API/main.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const bodyParser = require(`body-parser`);
|
||||
const multer = require("multer");
|
||||
const fs = require('fs');
|
||||
|
||||
const Actions = {
|
||||
'metadata': require(`./actions/metadata`),
|
||||
}
|
||||
|
||||
const FileCheckerAPI = class API {
|
||||
#paths = {
|
||||
"analyze": ["/api/fileanalyse"]
|
||||
}
|
||||
|
||||
// Constructor for the API class.
|
||||
constructor(INSTANCE) {
|
||||
this[`instance`] = INSTANCE;
|
||||
|
||||
const setConfig = () => {
|
||||
// Set up body-parser and multer.
|
||||
this[`instance`][`use`](bodyParser[`json`]());
|
||||
this[`instance`][`use`](bodyParser[`urlencoded`]({ extended: true }));
|
||||
const upload = multer({ dest: 'uploads/' });
|
||||
this[`instance`][`use`](upload.single('upfile'));
|
||||
}
|
||||
|
||||
setConfig();
|
||||
this.initRoutes();
|
||||
|
||||
};
|
||||
|
||||
// Set up the routes for the API.
|
||||
initRoutes() {
|
||||
this.#paths[`analyze`].forEach((PATH) => {
|
||||
[``, `.jsp`, `.php`, `.asp`, `.html`].forEach((SUFFIX) => {
|
||||
this[`instance`][`post`](PATH + SUFFIX, Actions.metadata.analyze);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FileCheckerAPI;
|
Loading…
Add table
Add a link
Reference in a new issue