Compare commits

..

2 Commits

Author SHA1 Message Date
Fred Boniface ef55fb0365 FullStack: Improve issue API
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-01-31 00:06:42 +00:00
Fred Boniface 205c6b5d6b Backend: Implement basic issue API
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-01-30 23:47:14 +00:00
7 changed files with 62 additions and 10 deletions

View File

@ -3,9 +3,8 @@
## Frontend:
* Alerts box should not be clickable, bar should be.
* Issue page: Submit using API.
* Issue page: Collect diagnostics such as browser features etc.
* Issue page: Captcha.
* Issue page: Check for success and then redirect to /.
* Enable text search for `locationName` on find-code page.
* Responsive text sizes for boards.
@ -18,6 +17,9 @@
* Write service worker for full PWA experience.
* Implement error pages.
* Issue page: Submit using API.
* Issue page: Collect diagnostics such as browser features etc.
* Add Gitea Issue API
## Backend:
@ -25,5 +27,7 @@
* DB Indexes:
- "stations": 3ALPHA, STANOX, TIPLOC
- "corpus": 3ALPHA, NLC, NLCDESC(TEXT)
* Add Gitea Issue API
* Add sanitizing to Gitea Issue API, currently considered to be unsafe.
* Add success test for Gitea Issue API and send the result onto the client.
* Rewrite sanitizing functions to remove external dependancy.
* Undo changed to make everything an array - frontend code to handle this.

6
app.js
View File

@ -4,6 +4,10 @@
// licensed separately, each folder contains a license file where a
// different license applies.
// While the Node app can serve static files, in production a separate
// container should be used for this. See the dockerfile under /static
// for this.
// External Requires
const express = require('express');
const app = express();
@ -15,6 +19,7 @@ const listRtr = require('./src/routes/list.routes'); // /list endpoints
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const findRtr = require('./src/routes/find.routes'); // /find endpoints
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
const initDb = require('./src/utils/dbinit.utils'); // DB Init Utility
// Set Server Configurations
@ -53,6 +58,7 @@ app.use('/api/v1/list', listRtr);
app.use('/api/v1/ldb', ldbRtr);
app.use('/api/v1/kube', kubeRtr);
app.use('/api/v1/find', findRtr);
app.use('/api/v1/issue', issueRtr);
// Start Express
app.listen(srvPort, srvListen, (error) =>{

View File

@ -0,0 +1,10 @@
module.exports = valid
const valid = [
"owlboard.co.uk",
"fjla.uk",
"gwr.com",
"swrailway.com",
"firstrail.com",
"networkrail.co.uk"
]

View File

@ -0,0 +1,14 @@
const issue = require('../services/issue.services');
async function post(req, res, next){
try {
res.json(await issue.processor(req.body))
} catch (err) {
console.error(`Controller Error`, err.message);
next(err);
}
}
module.exports = {
post
}

View File

@ -0,0 +1,7 @@
const express = require('express');
const router = express.Router();
const issueController = require('../controllers/issue.controllers');
router.post('/', issueController.post);
module.exports = router;

View File

@ -1,19 +1,29 @@
const axios = require('axios')
const clean = require('../utils/sanitizer.utils')
async function processor(data) {
let out = {}
out.title = await cleanData(data.subject)
out.body = await cleanData(data.msg)
sendToGitea(out);
}
async function cleanData(data) {
return data //clean.cleanApiEndpointTxt(data)
}
async function sendToGitea(body) {
let key = process.env.OWL_GIT_ISSUEBOT
let url = process.env.OWL_GIT_APIENDPOINT
let options = {
let opts = {
headers: {
Authorization: key
},
data: body,
withCredantials: true
}
}
await axios.post(url, options)
await axios.post(url, body, opts)
// Need to read the output from the POST and pass the result upwards to the client.
}
module.exports = {
sendToGitea
processor
}

View File

@ -52,6 +52,7 @@ async function cancel() {
async function send() {
setLoadingDesc("Sending\nData")
document.getElementById("preflight").style = "display: none"
showLoading()
var subject = sessionStorage.getItem("preflight_subject");
var msg = sessionStorage.getItem("preflight_msg")