POST for Application Settings working
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
const bodyParser = require("body-parser");
|
||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const applications = require('../src/apps.json');
|
|
||||||
const links = require('../src/links.json');
|
const links = require('../src/links.json');
|
||||||
const providers = require('../src/providers.json');
|
const providers = require('../src/providers.json');
|
||||||
const themes = require('../src/themes.json');
|
const themes = require('../src/themes.json');
|
||||||
@@ -14,10 +14,16 @@ const app = express();
|
|||||||
|
|
||||||
// initializing cors middleware for all routes
|
// initializing cors middleware for all routes
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
var jsonParser = bodyParser.json();
|
||||||
|
|
||||||
// creating route to make request to server for API
|
// creating route to make request to server for API
|
||||||
app.get("/sui/api/apps", (req, res) => {
|
app.get("/sui/api/apps", (req, res) => {
|
||||||
res.status(200).send(applications.apps);
|
fs.readFile('../src/apps.json', (err, data) => {
|
||||||
|
if (err) throw err;
|
||||||
|
let test = JSON.parse(data);
|
||||||
|
res.status(200).send(test.apps);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/sui/api/links", (req, res) => {
|
app.get("/sui/api/links", (req, res) => {
|
||||||
@@ -40,6 +46,13 @@ app.get("/sui/api/messages", (req, res) => {
|
|||||||
res.status(200).send(messages.messages);
|
res.status(200).send(messages.messages);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post("/sui/api/appUpdate", jsonParser, (req, res) => {
|
||||||
|
let data = JSON.stringify(req.body)
|
||||||
|
fs.writeFileSync('../src/apps.json',data)
|
||||||
|
var applications = require('../src/apps.json');
|
||||||
|
res.status(200).send(applications.apps)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// app is listening on port 5000
|
// app is listening on port 5000
|
||||||
|
|||||||
695
package-lock.json
generated
695
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -8,14 +8,18 @@
|
|||||||
"@testing-library/jest-dom": "^5.16.1",
|
"@testing-library/jest-dom": "^5.16.1",
|
||||||
"@testing-library/react": "^11.2.7",
|
"@testing-library/react": "^11.2.7",
|
||||||
"@testing-library/user-event": "^12.8.3",
|
"@testing-library/user-event": "^12.8.3",
|
||||||
|
"body-parser": "^1.20.0",
|
||||||
|
"chokidar": "^3.5.3",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.2",
|
"express": "^4.18.1",
|
||||||
|
"formik": "^2.2.9",
|
||||||
"history": "^5.1.0",
|
"history": "^5.1.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-router-dom": "^6.1.1",
|
"react-router-dom": "^6.1.1",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "4.0.3",
|
||||||
"web-vitals": "^1.1.2"
|
"web-vitals": "^1.1.2",
|
||||||
|
"yup": "^0.32.11"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|||||||
@@ -8,18 +8,14 @@ function ApplicationDetails(props) {
|
|||||||
} else {
|
} else {
|
||||||
nsfwChecked = false;
|
nsfwChecked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="applicationGrid" title={props.name}>
|
<div id="applicationGrid" title={props.name}>
|
||||||
<label htmlFor="name">Name</label>
|
<input id="name" className="settingsText" type="text" defaultValue={props.name}></input>
|
||||||
<input id="name" type="text" defaultValue={props.name}></input>
|
<input id="url" className="settingsText" type="text" defaultValue={props.url}></input>
|
||||||
<label htmlFor="url">URL</label>
|
<input id="icon" className="settingsText" type="text" defaultValue={props.icon}></input>
|
||||||
<input id="url" type="text" defaultValue={props.url}></input>
|
<input id="baseurl" className="settingsText" type="text" defaultValue={props.urlbase}></input>
|
||||||
<label htmlFor="icon">Icon</label>
|
<input id="NSFW" className="settingsCheckbox" type="checkbox" defaultChecked={nsfwChecked}></input>
|
||||||
<input id="icon" type="text" defaultValue={props.icon}></input>
|
|
||||||
<label htmlFor="baseurl">Base URL</label>
|
|
||||||
<input id="baseurl" type="text" defaultValue={props.urlbase}></input>
|
|
||||||
<label htmlFor="NSFW">NSFW</label>
|
|
||||||
<input id="NSFW" type="checkbox" defaultChecked={nsfwChecked}></input>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,19 +10,85 @@ const ApplicationSettings = () => {
|
|||||||
setState(data);
|
setState(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addRow = () => {
|
||||||
|
setState([
|
||||||
|
...state,
|
||||||
|
{ key: state.length +1,name: "", url: "home.halfaperture.com/", icon: "", urlbase: "/", NSFW: false}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData();
|
getData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
let names = []
|
||||||
|
let urls = []
|
||||||
|
let icons = []
|
||||||
|
let urlbases = []
|
||||||
|
let NSFWs = []
|
||||||
|
let exportData = {
|
||||||
|
apps: []
|
||||||
|
}
|
||||||
|
for (const item of e.target.form) {
|
||||||
|
if (item.type === "text") {
|
||||||
|
switch (item.id) {
|
||||||
|
case "name":
|
||||||
|
names.push(item.value)
|
||||||
|
break;
|
||||||
|
case "url":
|
||||||
|
urls.push(item.value)
|
||||||
|
break;
|
||||||
|
case "icon":
|
||||||
|
icons.push(item.value)
|
||||||
|
break;
|
||||||
|
case "baseurl":
|
||||||
|
urlbases.push(item.value)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (item.type === "checkbox") {
|
||||||
|
if (item.checked) {
|
||||||
|
NSFWs.push("NSFW")
|
||||||
|
} else {
|
||||||
|
NSFWs.push("SAFE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let index = 0; index < names.length; ++index) {
|
||||||
|
exportData.apps.push({
|
||||||
|
"name" : names[index],
|
||||||
|
"url" : urls[index],
|
||||||
|
"icon" : icons[index],
|
||||||
|
"baseurl" : urlbases[index],
|
||||||
|
"NSFW" : NSFWs[index]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let exportJSON = JSON.stringify(exportData)
|
||||||
|
const requestOptions = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: exportJSON
|
||||||
};
|
};
|
||||||
|
fetch("/sui/api/appUpdate", requestOptions)
|
||||||
|
.then(getData())
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="settings-panel">
|
<div id="settings-panel">
|
||||||
<div id="settings-panel-header">
|
<div id="settings-panel-header">
|
||||||
<h1>Applications</h1>
|
<h1>Applications</h1>
|
||||||
</div>
|
</div>
|
||||||
<form id="applicationForm">
|
<form id="applicationForm">
|
||||||
|
<div id="applicationHeader">
|
||||||
|
<div>Name</div>
|
||||||
|
<div>URL</div>
|
||||||
|
<div>Icon</div>
|
||||||
|
<div>Base URL</div>
|
||||||
|
<div>Hideable</div>
|
||||||
|
</div>
|
||||||
{state.map((apps) => (
|
{state.map((apps) => (
|
||||||
<ApplicationDetails
|
<ApplicationDetails
|
||||||
key={apps.name}
|
key={apps.name}
|
||||||
@@ -33,7 +99,9 @@ const ApplicationSettings = () => {
|
|||||||
NSFW={apps.NSFW}
|
NSFW={apps.NSFW}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
<button onClick={addRow} className="addRow">Add Application</button>
|
||||||
<button onClick={handleSubmit} type="submit" form="applicationForm" value="submit">Save</button>
|
<button onClick={handleSubmit} type="submit" form="applicationForm" value="submit">Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ function Applications() {
|
|||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
const response = await fetch("/sui/api/apps");
|
const response = await fetch("/sui/api/apps");
|
||||||
|
console.log(response)
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setState(data);
|
setState(data);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const BookmarksSettings = () => {
|
|||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
console.log(e);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div id="settings-panel">
|
<div id="settings-panel">
|
||||||
|
|||||||
@@ -537,26 +537,45 @@ table a{
|
|||||||
#applicationForm {
|
#applicationForm {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-column-gap: 1vh;
|
grid-column-gap: 1vh;
|
||||||
grid-row-gap: 1vh;
|
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
width: 100vh;
|
width: 100vh;
|
||||||
text-align: end;
|
text-align: end;
|
||||||
|
border-radius: 1em;
|
||||||
|
background-color: #FFFFFF33;
|
||||||
|
padding-bottom: 2em;
|
||||||
}
|
}
|
||||||
#applicationForm label {
|
#applicationForm div {
|
||||||
width: 100%;
|
font-size: larger;
|
||||||
|
padding-left: 1em;
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
|
padding-top: 1em;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
#applicationForm input {
|
#applicationForm input {
|
||||||
border: var(--color-border);
|
padding: 1em;
|
||||||
padding-left: 1em;
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
}
|
}
|
||||||
#applicationForm input:focus {
|
.settingsCheckbox:focus{
|
||||||
border: var(--color-border);
|
outline: none;
|
||||||
|
outline-style: none;
|
||||||
|
}
|
||||||
|
.settingsText:focus{
|
||||||
|
outline: auto;
|
||||||
|
outline-style: solid;
|
||||||
|
outline-color: var(--color-text-pri);
|
||||||
|
}
|
||||||
|
#applicationHeader {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 15% 40% 15% 15% 15%;
|
||||||
|
padding-left: 1em;
|
||||||
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
#applicationGrid {
|
#applicationGrid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 5% 10% 5% 30% 5% 10% 10% 10% 5% 5%;
|
grid-template-columns: 15% 40% 15% 15% 15%;
|
||||||
grid-row-gap: 1vh;
|
padding-left: 1em;
|
||||||
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bookmark Form */
|
/* Bookmark Form */
|
||||||
@@ -572,6 +591,7 @@ table a{
|
|||||||
#bookmarkForm label {
|
#bookmarkForm label {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
|
padding-top: 1em;
|
||||||
}
|
}
|
||||||
#bookmarkForm input {
|
#bookmarkForm input {
|
||||||
border: var(--color-border);
|
border: var(--color-border);
|
||||||
|
|||||||
Reference in New Issue
Block a user