-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathedit-info-server.js
More file actions
119 lines (113 loc) · 3.98 KB
/
Copy pathedit-info-server.js
File metadata and controls
119 lines (113 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require('fs');
const bodyParser = require('body-parser');
const iterateIntegs = require('./iterate-integrations');
const OVERRIDE_FILE = __dirname + '/../overrides.json';
const overrides = require(OVERRIDE_FILE);
const app = require('express')();
const list = {};
iterateIntegs((dir, name, integ) => {
console.log(name);
list[name] = Object.assign({}, {
title: integ.title,
description: integ.description,
logo: integ.logo,
}, overrides[name] || {});
})
function getHTML() {
return `
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
img {
height: 50px;
}
.submit-button {
position: fixed;
top: 50px;
right: 50px;
}
.integration {
padding: 15px;
margin-bottom: 15px;
border: 1px solid black;
border-radius: 4px;
}
.changed {
border-color: red;
}
</style>
</head>
<body>
<div class="container">
<form method="POST" action="/">
<div class="row">
<div class="col-xs-9">
${Object.keys(list).map(name => {
let o = overrides[name] || {};
let l = list[name];
let logo = (o.logo && o.logo.url) || (l.logo && l.logo.url) || '';
return `
<div class="integration">
<div class="row">
<div class="col-xs-6">
<h4>${name}</h4>
</div>
<div class="col-xs-6" style="background-color: ${(l.logo && l.logo.backgroundColor) || '#fff'}">
<img src="${logo}">
</div>
</div>
<label>Title</label>
<input class="form-control ${overrides[name] && overrides[name].title ? 'changed' : ''}"
type="text" name="${name}.title" value="${o.title || l.title}">
<br>
<label>Description</label>
<textarea class="form-control ${overrides[name] && overrides[name].description ? 'changed' : ''}"
name="${name}.description" rows="3">${o.description || l.description}</textarea>
<br>
<label>Logo</label>
<input class="form-control ${overrides[name] && overrides[name].logo ? 'changed' : ''}"
type="text" name="${name}.logo" value="${logo}">
</div>
`}).join('\n')}
</div>
</div>
<div class="col-xs-3">
<button class="btn btn-lg btn-success submit-button" type="submit">Update</button>
</div>
</form>
</div>
</body>
</html>
`
}
app.get('/', (req, res) => {
res.send(getHTML())
});
app.post('/', bodyParser.urlencoded({limit: '100mb', parameterLimit: 1000000}), (req, res) => {
for (let key in req.body) {
let [name, field] = key.split('.');
let l = list[name];
let o = overrides[name] || {};
let val = req.body[key];
if (!val) {
delete o[field];
continue;
}
val = val.replace(new RegExp(String.fromCharCode(13), 'g'), '');
if (field === 'logo') {
if ((!l.logo || l.logo.url !== val) && (!o.logo || o.logo.url !== val)) {
console.log('changing', name, field);
overrides[name] = overrides[name] || {};
overrides[name].logo = {url: val};
}
} else if ((l[field] || '').trim() !== val.trim() && (o[field] || '').trim() !== val.trim()) {
console.log('changing', name, field);
overrides[name] = overrides[name] || {};
overrides[name][field] = val;
}
}
fs.writeFileSync(OVERRIDE_FILE, JSON.stringify(overrides, null, 2))
res.send(getHTML());
})
app.listen(3000, () => console.log("Listening on 3000"));