neutral-old/routes/cv.js
Raphix 9982f1f1bf
All checks were successful
Neutral/pipeline/head This commit looks good
Fix CV EDITOR
2023-03-27 22:03:55 +02:00

381 lines
12 KiB
JavaScript

var express = require('express');
var router = express.Router();
var ntr = require("../neutral-functions.js")
var fs = require("fs")
var path = require("path")
var mime = require('mime-types');
const { compileString } = require('sass');
const { response } = require('../app.js');
/* GET home page. */
router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check.name != false) {
res.redirect(302, "/")
} else {
res.render('login', {error: ""});
}
});
router.post("/", function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check.name == false) {
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
} else {
if(check.permLevel >= 2) {
const bod = req.body
if(bod.request == "get") {
const markdownFolder = "/home/gitlab-ci/cv/dashboard-raphael/markdown/"
if(bod.value == "WHOAMI") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "whoami.md")
} else {
fileData = fs.readFileSync("../MD_TEST/whoami.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.value == "CONTACT") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "info.md")
} else {
fileData = fs.readFileSync("../MD_TEST/info.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.value == "FORMATION") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "formation.md")
} else {
fileData = fs.readFileSync("../MD_TEST/formation.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.value == "DIPLOME") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "certif.md")
} else {
fileData = fs.readFileSync("../MD_TEST/certif.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.value == "LOBBIES") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "passions.md")
} else {
fileData = fs.readFileSync("../MD_TEST/passions.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.value == "FIND") {
var fileData = null;
if(fs.existsSync(markdownFolder)) {
fileData = fs.readFileSync(markdownFolder + "find.md")
} else {
fileData = fs.readFileSync("../MD_TEST/find.md")
}
res.send({"result":"success", "content":fileData.toString()})
} else {
res.send({"result":"failed", "content":"ERROR_NOT_VALID_REQUEST"})
}
} else if(bod.request == "set") {
const markdownFolder = "/home/gitlab-ci/cv/dashboard-raphael/markdown/"
if(bod.type == "WHOAMI") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "whoami.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/whoami.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
} else if(bod.type == "CONTACT") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "info.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/info.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
res.send({"result":"success", "content":fileData.toString()})
} else if(bod.type == "FORMATION") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "formation.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/formation.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
} else if(bod.type == "DIPLOME") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "certif.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/certif.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
} else if(bod.type == "LOBBIES") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "passions.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/passions.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
} else if(bod.type == "FIND") {
if(fs.existsSync(markdownFolder)) {
fs.writeFile(markdownFolder + "find.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
} else {
fs.writeFile("../MD_TEST/find.md", bod.value, (err) => {
if(err) {
res.send({"result":"success", "content":"ERROR_NOT_PERMITTED"})
console.log(err)
} else {
res.send({"result":"success", "content":"NO_PROBLEM"})
console.log(err)
}
})
}
} else {
res.send({"result":"failed", "content":"ERROR_NOT_VALID_REQUEST"})
}
}
} else {
res.send({"result":"failed", "content":"ERROR_USER_PERMISSION_TOO_LOW"})
}
}
})
module.exports = router;