FullStack: Add response to issue API

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-31 11:32:35 +00:00
parent 8213eacde5
commit bbdaf4308a
3 changed files with 28 additions and 19 deletions

View File

@ -4,7 +4,6 @@
* Alerts box should not be clickable, bar should be.
* 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.
@ -19,7 +18,10 @@
* Implement error pages.
* Issue page: Submit using API.
* Issue page: Collect diagnostics such as browser features etc.
* Add sanitizing to Gitea Issue API, currently considered to be unsafe.
* Add Gitea Issue API
* Issue page: Check for success and then redirect to /.
* Add success test for Gitea Issue API and send the result onto the client.
## Backend:
@ -27,7 +29,5 @@
* DB Indexes:
- "stations": 3ALPHA, STANOX, TIPLOC
- "corpus": 3ALPHA, NLC, NLCDESC(TEXT)
* 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.

View File

@ -1,17 +1,12 @@
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)
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
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
@ -20,8 +15,13 @@ async function sendToGitea(body) {
Authorization: key
}
}
await axios.post(url, body, opts)
var res = await axios.post(url, body, opts)
// Need to read the output from the POST and pass the result upwards to the client.
if (res.status == 201) {
return {status: res.status,message:"issue created"}
} else {
return {status: res.status,message:"issue not created"}
}
}
module.exports = {

View File

@ -37,8 +37,7 @@ async function preflight(data) {
\nlocalStorage Avail: ${data.browserData.localStorage}
\nsessionStorage Avail: ${data.browserData.sessionStorage}
\nViewport size: ${data.browserData.viewport}
\nUser message:\n
${data.formData.message}`
\nUser message:\n\n${data.formData.message}`
document.getElementById("pre_message").innerText = pre_msg
hideLoading()
document.getElementById("preflight").style = "display: block"
@ -73,6 +72,16 @@ async function send() {
redirect: 'follow',
body: payload
}
await fetch("/api/v1/issue", opt)
hideLoading();
var res = await fetch("/api/v1/issue", opt)
if (res.status == 200) {
setLoadingDesc("Success")
await delay(2500)
window.location.replace("/")
} else {
setLoadingDesc("Error")
navigator.vibrate(1500)
await delay(2500)
hideLoading()
document.getElementById("preflight").style = "display: none;"
}
}