mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-26 22:43:07 +00:00
Compare commits
279 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9e15746c3 | ||
|
|
1fff75cc5e | ||
|
|
9037cf1750 | ||
|
|
dfe26280d2 | ||
|
|
7894d9fbec | ||
|
|
c3173d2e14 | ||
|
|
4859756ef8 | ||
|
|
1c47d743d6 | ||
|
|
bfbbbe9e86 | ||
|
|
1aaa146412 | ||
|
|
086d85c08b | ||
|
|
134fe7d372 | ||
|
|
836dfbade2 | ||
|
|
52a7ce9866 | ||
|
|
05f3f40e47 | ||
|
|
7cad7fd319 | ||
|
|
dca9099d00 | ||
|
|
fa78d04e89 | ||
|
|
5f9dfc9258 | ||
|
|
d534eddb29 | ||
|
|
9099db5ea1 | ||
|
|
a9a8b4b9bb | ||
|
|
5d29d40c97 | ||
|
|
4291284252 | ||
|
|
fcede5448e | ||
|
|
c47974cb49 | ||
|
|
4fde4600bc | ||
|
|
27f939201d | ||
|
|
6e2cde507d | ||
|
|
95d6e39a44 | ||
|
|
39b8cbae2a | ||
|
|
0162232053 | ||
|
|
00f1d4a27e | ||
|
|
db618fe2ad | ||
|
|
47f2703388 | ||
|
|
52e929ee68 | ||
|
|
f74e72a35f | ||
|
|
e3d256aaaf | ||
|
|
f65dee28cb | ||
|
|
58dd1b147d | ||
|
|
f84dcd9fce | ||
|
|
cc1ab35255 | ||
|
|
803ca09ab6 | ||
|
|
8a60a4a5cc | ||
|
|
a345b67ffe | ||
|
|
456cefd535 | ||
|
|
ab6861675d | ||
|
|
0deb9073cd | ||
|
|
d5cda45d4d | ||
|
|
36674f4cf2 | ||
|
|
618de544bf | ||
|
|
8f5b421531 | ||
|
|
8db12739d3 | ||
|
|
4cb093c0c0 | ||
|
|
9f0f9a9169 | ||
|
|
a9aab5bb0c | ||
|
|
5ca970bdee | ||
|
|
9635e1a8eb | ||
|
|
23e3c98a0d | ||
|
|
346bb0086e | ||
|
|
e873dcf3a8 | ||
|
|
269dd6107c | ||
|
|
8281db8543 | ||
|
|
66db3ecdc1 | ||
|
|
1ef61b32d4 | ||
|
|
dc66d36b2d | ||
|
|
0bd3b53dd1 | ||
|
|
5651c66562 | ||
|
|
fb2d03f5a2 | ||
|
|
0b44e68a36 | ||
|
|
fe7ee78cae | ||
|
|
aa68762294 | ||
|
|
2a9402634f | ||
|
|
291e16b124 | ||
|
|
e75eb72d3f | ||
|
|
7bf95dd0ca | ||
|
|
80a21e3f27 | ||
|
|
a921d0a9bb | ||
|
|
9acecb63ed | ||
|
|
a6efaf0e8b | ||
|
|
c4b754e467 | ||
|
|
e82411d3d2 | ||
|
|
5080fd068a | ||
|
|
88d36bcf85 | ||
|
|
e2243efe82 | ||
|
|
337531a622 | ||
|
|
7e165c6e61 | ||
|
|
5d9ef3fa6c | ||
|
|
24bffacaeb | ||
|
|
1e38ed8d1f | ||
|
|
25ce1aa00c | ||
|
|
97f8493319 | ||
|
|
c9241e3091 | ||
|
|
70118022b8 | ||
|
|
226e714f32 | ||
|
|
f3332fb95b | ||
|
|
10d4cd4ab3 | ||
|
|
2a523c4955 | ||
|
|
64dd71601c | ||
|
|
4968300e7a | ||
|
|
3acb25ce3a | ||
|
|
487a574f50 | ||
|
|
a4e0f1fc0f | ||
|
|
2ada6ce70d | ||
|
|
132878fd8c | ||
|
|
0146ab7ce0 | ||
|
|
a29addbfa3 | ||
|
|
796f8ac8b7 | ||
|
|
19d76bd077 | ||
|
|
f59a250bb1 | ||
|
|
5b64052c21 | ||
|
|
f00e76319c | ||
|
|
a844b29165 | ||
|
|
fcd1a2de5b | ||
|
|
5eb1456915 | ||
|
|
a82e9758b3 | ||
|
|
6adac74f76 | ||
|
|
3c3b4d8466 | ||
|
|
9cc4d2d7c5 | ||
|
|
d216216df7 | ||
|
|
9fd92e00a1 | ||
|
|
afeadb5417 | ||
|
|
e9286d4bb7 | ||
|
|
22dbe1ebf0 | ||
|
|
53761bc567 | ||
|
|
e6e9029bb7 | ||
|
|
1a325fb3c5 | ||
|
|
84f49aebce | ||
|
|
8949248bc4 | ||
|
|
df06d8fcd3 | ||
|
|
d6ca6592a2 | ||
|
|
0110c6afed | ||
|
|
0e29620710 | ||
|
|
c33b44855a | ||
|
|
77f162f7a4 | ||
|
|
bc475b5ed9 | ||
|
|
0415af624a | ||
|
|
8a63859546 | ||
|
|
8d5bc9e37c | ||
|
|
313f18c74c | ||
|
|
0c6bc5d7ac | ||
|
|
db6c689914 | ||
|
|
d4970ed119 | ||
|
|
e7e35294c6 | ||
|
|
e9c45b216c | ||
|
|
40925253bd | ||
|
|
66433d9e77 | ||
|
|
3a6750613b | ||
|
|
e45fddad60 | ||
|
|
a7361f8450 | ||
|
|
32fa272947 | ||
|
|
68895bdca2 | ||
|
|
8ab6a8599d | ||
|
|
ea656e5119 | ||
|
|
570c850c4f | ||
|
|
17dfacd5c9 | ||
|
|
ab32695ac9 | ||
|
|
672b787cd5 | ||
|
|
931566636b | ||
|
|
ffaca4ec10 | ||
|
|
fabc0bea83 | ||
|
|
5c2ad7dfee | ||
|
|
3e7d4714a2 | ||
|
|
77c4ac6640 | ||
|
|
a7c892c1bb | ||
|
|
dca7086522 | ||
|
|
6c42a7e180 | ||
|
|
e8c2858154 | ||
|
|
84f84782f5 | ||
|
|
3caec793d8 | ||
|
|
9717f0cd66 | ||
|
|
0cdc1947c1 | ||
|
|
f024bea493 | ||
|
|
bbe4b5f978 | ||
|
|
14d2534542 | ||
|
|
3b49b5180e | ||
|
|
2028f3dccd | ||
|
|
8e4fc01831 | ||
|
|
e2ae6898fd | ||
|
|
44262e2aae | ||
|
|
d8e174e143 | ||
|
|
0d2878a7e7 | ||
|
|
a0d043439c | ||
|
|
8126271ea3 | ||
|
|
67e265b23f | ||
|
|
dc67c75130 | ||
|
|
ebc3b4ee66 | ||
|
|
9bf28f1433 | ||
|
|
dbbfb0b628 | ||
|
|
4f2c2916d6 | ||
|
|
629b51a26c | ||
|
|
d947ff45e2 | ||
|
|
a2d260c297 | ||
|
|
c411691fd6 | ||
|
|
f40c5e17ca | ||
|
|
a2497052b4 | ||
|
|
240dfa3954 | ||
|
|
d19aaf6c78 | ||
|
|
235969a485 | ||
|
|
2e459118aa | ||
|
|
ff60ca163f | ||
|
|
4dc5746c71 | ||
|
|
5cf8715dea | ||
|
|
849e5d5d1a | ||
|
|
188090ee45 | ||
|
|
d352b76efe | ||
|
|
e88272c684 | ||
|
|
10ce696333 | ||
|
|
4488fe36db | ||
|
|
c79765396d | ||
|
|
36549f3224 | ||
|
|
e81a9dab1f | ||
|
|
65759e18bd | ||
|
|
f458b98dcf | ||
|
|
cc7fe99760 | ||
|
|
78642e514d | ||
|
|
4edbfa10b5 | ||
|
|
5e8f74b9bc | ||
|
|
b39e8eea16 | ||
|
|
0c6c0c9fd6 | ||
|
|
51d3d11bff | ||
|
|
46882c4fb4 | ||
|
|
760c1a9e8c | ||
|
|
baf201cc3a | ||
|
|
e2ce1185b6 | ||
|
|
8983d74775 | ||
|
|
f084c11936 | ||
|
|
a442817226 | ||
|
|
73e579703a | ||
|
|
4680e7a5cc | ||
|
|
f07252d670 | ||
|
|
f15c831b70 | ||
|
|
587831652c | ||
|
|
6e0aff525f | ||
|
|
748c25aae4 | ||
|
|
f675fd130f | ||
|
|
a69d251f53 | ||
|
|
7ed48f3e70 | ||
|
|
627b4ace0f | ||
|
|
f2d5a8df99 | ||
|
|
0d8026436c | ||
|
|
8656feba44 | ||
|
|
e9a76dd018 | ||
|
|
db0f75c852 | ||
|
|
0db6ffe340 | ||
|
|
1b855108bf | ||
|
|
ffe12ebee7 | ||
|
|
e211b0858d | ||
|
|
c8ac3f36fd | ||
|
|
8c0cf4ccd4 | ||
|
|
79eb4d8a9a | ||
|
|
52d5d17561 | ||
|
|
0fc3e03e95 | ||
|
|
28cadcad06 | ||
|
|
1fd8648602 | ||
|
|
66e10f3b4e | ||
|
|
da0372e44c | ||
|
|
a4e6b2358a | ||
|
|
24adbdc429 | ||
|
|
ccd5cacb0c | ||
|
|
5e2171ceb1 | ||
|
|
b00a962e77 | ||
|
|
c518fc2d23 | ||
|
|
ca2582fdbd | ||
|
|
04916d8931 | ||
|
|
f781c2bd56 | ||
|
|
8adf5ce463 | ||
|
|
94afbe5417 | ||
|
|
9e169aba91 | ||
|
|
f5c7761c61 | ||
|
|
ec040cc2bb | ||
|
|
42125f4041 | ||
|
|
a499bb3a54 | ||
|
|
35b4c354f2 | ||
|
|
b8fd8a7a86 | ||
|
|
620cb95ae8 | ||
|
|
f66664a3e2 | ||
|
|
d7ee004127 | ||
|
|
4a449c7895 |
@@ -10,7 +10,7 @@ orbs:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.8.0
|
- image: cimg/node:20.17.0
|
||||||
- image: mongo:4.4
|
- image: mongo:4.4
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
# fallback to using the latest cache if no exact match is found
|
# fallback to using the latest cache if no exact match is found
|
||||||
- v1-dependencies-
|
- v1-dependencies-
|
||||||
|
|
||||||
- run: sudo npm install -g npm@10.2.0
|
- run: sudo npm install -g npm@10.8.2
|
||||||
- node/install-packages:
|
- node/install-packages:
|
||||||
app-dir: ~/homebrewery
|
app-dir: ~/homebrewery
|
||||||
cache-path: node_modules
|
cache-path: node_modules
|
||||||
@@ -45,7 +45,7 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.8.0
|
- image: cimg/node:20.17.0
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
parallelism: 1
|
parallelism: 1
|
||||||
|
|||||||
@@ -2,35 +2,44 @@ require('./admin.less');
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
|
const BrewUtils = require('./brewUtils/brewUtils.jsx');
|
||||||
|
const NotificationUtils = require('./notificationUtils/notificationUtils.jsx');
|
||||||
|
|
||||||
const BrewCleanup = require('./brewCleanup/brewCleanup.jsx');
|
const tabGroups = ['brew', 'notifications'];
|
||||||
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
|
||||||
const BrewCompress = require ('./brewCompress/brewCompress.jsx');
|
|
||||||
const Stats = require('./stats/stats.jsx');
|
|
||||||
|
|
||||||
const Admin = createClass({
|
const Admin = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState : function(){
|
||||||
|
return ({
|
||||||
|
currentTab : 'brew'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleClick : function(newTab){
|
||||||
|
if(this.state.currentTab === newTab) return;
|
||||||
|
this.setState({
|
||||||
|
currentTab : newTab
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='admin'>
|
return <div className='admin'>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div className='container'>
|
<div className='container'>
|
||||||
<i className='fas fa-rocket' />
|
<i className='fas fa-rocket' />
|
||||||
homebrewery admin
|
homebrewery admin
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div className='container'>
|
<main className='container'>
|
||||||
<Stats />
|
<nav className='tabs'>
|
||||||
<hr />
|
{tabGroups.map((tab, idx)=>{ return <button className={tab===this.state.currentTab ? 'active' : ''} key={idx} onClick={()=>{ return this.handleClick(tab); }}>{tab.toUpperCase()}</button>; })}
|
||||||
<BrewLookup />
|
</nav>
|
||||||
<hr />
|
{this.state.currentTab==='brew' && <BrewUtils />}
|
||||||
<BrewCleanup />
|
{this.state.currentTab==='notifications' && <NotificationUtils />}
|
||||||
<hr />
|
</main>
|
||||||
<BrewCompress />
|
|
||||||
</div>
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,39 +6,95 @@
|
|||||||
|
|
||||||
@import 'font-awesome/css/font-awesome.css';
|
@import 'font-awesome/css/font-awesome.css';
|
||||||
|
|
||||||
html,body, #reactContainer, .naturalCrit{
|
html,body, #reactContainer, .naturalCrit { min-height : 100%; }
|
||||||
min-height : 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@sidebarWidth : 250px;
|
@sidebarWidth : 250px;
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color : #eee;
|
|
||||||
font-family : 'Open Sans', sans-serif;
|
|
||||||
color : #4b5055;
|
|
||||||
font-weight : 100;
|
|
||||||
text-rendering : optimizeLegibility;
|
|
||||||
margin : 0;
|
|
||||||
padding : 0;
|
|
||||||
height : 100%;
|
height : 100%;
|
||||||
|
padding : 0;
|
||||||
|
margin : 0;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
font-weight : 100;
|
||||||
|
color : #4B5055;
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
text-rendering : optimizeLegibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin{
|
:where(.admin) {
|
||||||
|
|
||||||
header {
|
header {
|
||||||
background-color : @red;
|
|
||||||
font-size: 2em;
|
|
||||||
padding : 20px 0px;
|
padding : 20px 0px;
|
||||||
color : white;
|
|
||||||
margin-bottom : 30px;
|
margin-bottom : 30px;
|
||||||
i{
|
font-size : 2em;
|
||||||
margin-right: 30px;
|
color : white;
|
||||||
|
background-color : @red;
|
||||||
|
i { margin-right : 30px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
hr { margin : 30px 0px; }
|
||||||
|
|
||||||
|
:where(.container) {
|
||||||
|
input {
|
||||||
|
height : 33px;
|
||||||
|
padding : 0px 10px;
|
||||||
|
margin-bottom : 20px;
|
||||||
|
font-family : monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
height : 37px;
|
||||||
|
vertical-align : middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl {
|
||||||
|
@maxItemWidth : 132px;
|
||||||
|
dt {
|
||||||
|
float : left;
|
||||||
|
width : @maxItemWidth;
|
||||||
|
clear : left;
|
||||||
|
text-align : right;
|
||||||
|
&::after { content : ' : '; }
|
||||||
|
}
|
||||||
|
dd {
|
||||||
|
height : 1em;
|
||||||
|
padding : 0 0 0.5em 0;
|
||||||
|
margin-left : @maxItemWidth + 6px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hr{
|
.tabs button {
|
||||||
margin : 30px 0px;
|
margin-right : 3px;
|
||||||
|
margin-left : 3px;
|
||||||
|
color : black;
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
border : 1px solid #444444;
|
||||||
|
border-radius : 5px;
|
||||||
|
&:hover {
|
||||||
|
color : #EEEEEE;
|
||||||
|
background-color : #444444;
|
||||||
|
}
|
||||||
|
&.active {
|
||||||
|
margin-right : 2px;
|
||||||
|
margin-left : 2px;
|
||||||
|
text-decoration : underline;
|
||||||
|
background-color : #CCCCCC;
|
||||||
|
border : 2px solid #444444;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notificationUtils {
|
||||||
|
display : flex;
|
||||||
|
gap : 50px;
|
||||||
|
justify-content : space-between;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background: rgb(178, 54, 54);
|
||||||
|
color:white;
|
||||||
|
font-weight: 900;
|
||||||
|
margin-block:10px;
|
||||||
|
padding:10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
.BrewCleanup{
|
|
||||||
.removeBox{
|
|
||||||
margin-top: 20px;
|
|
||||||
button{
|
|
||||||
background-color: @red;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
.BrewCompress{
|
|
||||||
.removeBox{
|
|
||||||
margin-top: 20px;
|
|
||||||
button{
|
|
||||||
background-color: @red;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
.brewLookup{
|
|
||||||
input{
|
|
||||||
height : 33px;
|
|
||||||
margin-bottom : 20px;
|
|
||||||
padding : 0px 10px;
|
|
||||||
font-family : monospace;
|
|
||||||
}
|
|
||||||
button{
|
|
||||||
vertical-align : middle;
|
|
||||||
height : 37px;
|
|
||||||
}
|
|
||||||
dl{
|
|
||||||
@maxItemWidth : 132px;
|
|
||||||
dt{
|
|
||||||
float : left;
|
|
||||||
clear : left;
|
|
||||||
width : @maxItemWidth;
|
|
||||||
text-align : right;
|
|
||||||
&::after {
|
|
||||||
content: " : ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dd{
|
|
||||||
height : 1em;
|
|
||||||
margin-left : @maxItemWidth + 6px;
|
|
||||||
padding : 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
9
client/admin/brewUtils/brewCleanup/brewCleanup.less
Normal file
9
client/admin/brewUtils/brewCleanup/brewCleanup.less
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.BrewCleanup {
|
||||||
|
.removeBox {
|
||||||
|
margin-top : 20px;
|
||||||
|
button {
|
||||||
|
margin-right : 10px;
|
||||||
|
background-color : @red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
client/admin/brewUtils/brewCompress/brewCompress.less
Normal file
9
client/admin/brewUtils/brewCompress/brewCompress.less
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.BrewCompress {
|
||||||
|
.removeBox {
|
||||||
|
margin-top : 20px;
|
||||||
|
button {
|
||||||
|
margin-right : 10px;
|
||||||
|
background-color : @red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
require('./brewLookup.less');
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
24
client/admin/brewUtils/brewUtils.jsx
Normal file
24
client/admin/brewUtils/brewUtils.jsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
|
|
||||||
|
const BrewCleanup = require('./brewCleanup/brewCleanup.jsx');
|
||||||
|
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
||||||
|
const BrewCompress = require ('./brewCompress/brewCompress.jsx');
|
||||||
|
const Stats = require('./stats/stats.jsx');
|
||||||
|
|
||||||
|
const BrewUtils = createClass({
|
||||||
|
render : function(){
|
||||||
|
return <>
|
||||||
|
<Stats />
|
||||||
|
<hr />
|
||||||
|
<BrewLookup />
|
||||||
|
<hr />
|
||||||
|
<BrewCleanup />
|
||||||
|
<hr />
|
||||||
|
<BrewCompress />
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = BrewUtils;
|
||||||
13
client/admin/brewUtils/stats/stats.less
Normal file
13
client/admin/brewUtils/stats/stats.less
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
.Stats {
|
||||||
|
position : relative;
|
||||||
|
|
||||||
|
.pending {
|
||||||
|
position : absolute;
|
||||||
|
top : 0px;
|
||||||
|
left : 0px;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
background-color : rgba(238,238,238, 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
require('./notificationAdd.less');
|
||||||
|
const React = require('react');
|
||||||
|
const { useState, useRef } = require('react');
|
||||||
|
const request = require('superagent');
|
||||||
|
|
||||||
|
const NotificationAdd = ()=>{
|
||||||
|
const [notificationResult, setNotificationResult] = useState(null);
|
||||||
|
const [searching, setSearching] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const dismissKeyRef = useRef(null);
|
||||||
|
const titleRef = useRef(null);
|
||||||
|
const textRef = useRef(null);
|
||||||
|
const startAtRef = useRef(null);
|
||||||
|
const stopAtRef = useRef(null);
|
||||||
|
|
||||||
|
const saveNotification = async ()=>{
|
||||||
|
const dismissKey = dismissKeyRef.current.value;
|
||||||
|
const title = titleRef.current.value;
|
||||||
|
const text = textRef.current.value;
|
||||||
|
const startAt = new Date(startAtRef.current.value);
|
||||||
|
const stopAt = new Date(stopAtRef.current.value);
|
||||||
|
|
||||||
|
// Basic validation
|
||||||
|
if(!dismissKey || !title || !text || isNaN(startAt.getTime()) || isNaN(stopAt.getTime())) {
|
||||||
|
setError('All fields are required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(startAt >= stopAt) {
|
||||||
|
setError('End date must be after the start date!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
dismissKey,
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
startAt : startAt?.toISOString() ?? '',
|
||||||
|
stopAt : stopAt?.toISOString() ?? '',
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
setSearching(true);
|
||||||
|
setError(null);
|
||||||
|
const response = await request.post('/admin/notification/add').send(data);
|
||||||
|
console.log(response.body);
|
||||||
|
|
||||||
|
// Reset form fields
|
||||||
|
dismissKeyRef.current.value = '';
|
||||||
|
titleRef.current.value = '';
|
||||||
|
textRef.current.value = '';
|
||||||
|
|
||||||
|
setNotificationResult('Notification successfully created.');
|
||||||
|
setSearching(false);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.response.body.message);
|
||||||
|
setError(`Error saving notification: ${err.response.body.message}`);
|
||||||
|
setSearching(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='notificationAdd'>
|
||||||
|
<h2>Add Notification</h2>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Dismiss Key:
|
||||||
|
<input className='fieldInput' type='text' ref={dismissKeyRef} required
|
||||||
|
placeholder='GOOGLEDRIVENOTIF'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Title:
|
||||||
|
<input className='fieldInput' type='text' ref={titleRef} required
|
||||||
|
placeholder='Stop using Google Drive as image host'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Text:
|
||||||
|
<textarea className='fieldInput' type='text' ref={textRef} required
|
||||||
|
placeholder='Google Drive is not an image hosting site, you should not use it as such.'
|
||||||
|
>
|
||||||
|
</textarea>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Start Date:
|
||||||
|
<input type='date' className='fieldInput' ref={startAtRef} required/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
End Date:
|
||||||
|
<input type='date' className='fieldInput' ref={stopAtRef} required/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className='notificationResult'>{notificationResult}</div>
|
||||||
|
|
||||||
|
<button className='notificationSave' onClick={saveNotification} disabled={searching}>
|
||||||
|
<i className={`fas ${searching ? 'fa-spin fa-spinner' : 'fa-save'}`}/>
|
||||||
|
Save Notification
|
||||||
|
</button>
|
||||||
|
{error && <div className='error'>{error}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationAdd;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
.notificationAdd {
|
||||||
|
position : relative;
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
width : 500px;
|
||||||
|
|
||||||
|
.field {
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : 120px 150px;
|
||||||
|
align-items : center;
|
||||||
|
justify-items : stretch;
|
||||||
|
width : 100%;
|
||||||
|
margin-bottom : 20px;
|
||||||
|
|
||||||
|
|
||||||
|
input {
|
||||||
|
height : 33px;
|
||||||
|
padding : 0px 10px;
|
||||||
|
margin-bottom : unset;
|
||||||
|
font-family : monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width : 50ch;
|
||||||
|
min-height : 7em;
|
||||||
|
max-height : 20em;
|
||||||
|
resize : vertical;
|
||||||
|
padding : 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 200px;
|
||||||
|
|
||||||
|
i { margin-right : 10px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
require('./notificationLookup.less');
|
||||||
|
|
||||||
|
const React = require('react');
|
||||||
|
const { useState } = require('react');
|
||||||
|
const request = require('superagent');
|
||||||
|
const Moment = require('moment');
|
||||||
|
|
||||||
|
const NotificationDetail = ({ notification, onDelete })=>(
|
||||||
|
<>
|
||||||
|
<dl>
|
||||||
|
<dt>Key</dt>
|
||||||
|
<dd>{notification.dismissKey}</dd>
|
||||||
|
|
||||||
|
<dt>Title</dt>
|
||||||
|
<dd>{notification.title || 'No Title'}</dd>
|
||||||
|
|
||||||
|
<dt>Text</dt>
|
||||||
|
<dd>{notification.text || 'No Text'}</dd>
|
||||||
|
|
||||||
|
<dt>Created</dt>
|
||||||
|
<dd>{Moment(notification.createdAt).format('LLLL')}</dd>
|
||||||
|
|
||||||
|
<dt>Start</dt>
|
||||||
|
<dd>{Moment(notification.startAt).format('LLLL') || 'No Start Time'}</dd>
|
||||||
|
|
||||||
|
<dt>Stop</dt>
|
||||||
|
<dd>{Moment(notification.stopAt).format('LLLL') || 'No End Time'}</dd>
|
||||||
|
</dl>
|
||||||
|
<button onClick={()=>onDelete(notification.dismissKey)}>DELETE</button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const NotificationLookup = ()=>{
|
||||||
|
const [searching, setSearching] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [notifications, setNotifications] = useState([]);
|
||||||
|
|
||||||
|
const lookupAll = async ()=>{
|
||||||
|
setSearching(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await request.get('/admin/notification/all');
|
||||||
|
setNotifications(res.body || []);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setError(`Error looking up notifications: ${err.response.body.message}`);
|
||||||
|
} finally {
|
||||||
|
setSearching(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteNotification = async (dismissKey)=>{
|
||||||
|
if(!dismissKey) return;
|
||||||
|
|
||||||
|
const confirmed = window.confirm(
|
||||||
|
`Really delete notification ${dismissKey}?`
|
||||||
|
);
|
||||||
|
if(!confirmed) {
|
||||||
|
console.log('Delete notification cancelled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Delete notification confirm');
|
||||||
|
try {
|
||||||
|
await request.delete(`/admin/notification/delete/${dismissKey}`);
|
||||||
|
lookupAll();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setError(`Error deleting notification: ${err.response.body.message}`);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderNotificationsList = ()=>{
|
||||||
|
if(error)
|
||||||
|
return <div className='error'>{error}</div>;
|
||||||
|
|
||||||
|
if(notifications.length === 0)
|
||||||
|
return <div className='noNotification'>No notifications available.</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul className='notificationList'>
|
||||||
|
{notifications.map((notification)=>(
|
||||||
|
<li key={notification.dismissKey} >
|
||||||
|
<details>
|
||||||
|
<summary>{notification.title || 'No Title'}</summary>
|
||||||
|
<NotificationDetail notification={notification} onDelete={deleteNotification} />
|
||||||
|
</details>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='notificationLookup'>
|
||||||
|
<h2>Check all Notifications</h2>
|
||||||
|
<button onClick={lookupAll}>
|
||||||
|
<i className={`fas ${searching ? 'fa-spin fa-spinner' : 'fa-search'}`} />
|
||||||
|
</button>
|
||||||
|
{renderNotificationsList()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationLookup;
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
.notificationLookup {
|
||||||
|
width : 450px;
|
||||||
|
height : fit-content;
|
||||||
|
|
||||||
|
.notificationList {
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
max-height : 500px;
|
||||||
|
margin-block : 20px;
|
||||||
|
overflow : auto;
|
||||||
|
border : 1px solid;
|
||||||
|
border-radius : 5px;
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding : 10px;
|
||||||
|
background : #CCCCCC;
|
||||||
|
|
||||||
|
&:nth-child(even) { background : #DDDDDD; }
|
||||||
|
&:first-child {
|
||||||
|
border-top-left-radius : 5px;
|
||||||
|
border-top-right-radius : 5px;
|
||||||
|
}
|
||||||
|
&:last-child {
|
||||||
|
border-bottom-right-radius : 5px;
|
||||||
|
border-bottom-left-radius : 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
font-size : 20px;
|
||||||
|
font-weight : 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl dt{
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.noNotification { margin-block : 20px; }
|
||||||
|
}
|
||||||
15
client/admin/notificationUtils/notificationUtils.jsx
Normal file
15
client/admin/notificationUtils/notificationUtils.jsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const React = require('react');
|
||||||
|
|
||||||
|
const NotificationLookup = require('./notificationLookup/notificationLookup.jsx');
|
||||||
|
const NotificationAdd = require('./notificationAdd/notificationAdd.jsx');
|
||||||
|
|
||||||
|
const NotificationUtils = ()=>{
|
||||||
|
return (
|
||||||
|
<section className='notificationUtils'>
|
||||||
|
<NotificationAdd />
|
||||||
|
<NotificationLookup />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationUtils;
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
.Stats{
|
|
||||||
position : relative;
|
|
||||||
.pending{
|
|
||||||
position : absolute;
|
|
||||||
top : 0px;
|
|
||||||
left : 0px;
|
|
||||||
height : 100%;
|
|
||||||
width : 100%;
|
|
||||||
background-color : rgba(238,238,238, 0.5);
|
|
||||||
}
|
|
||||||
dl{
|
|
||||||
@maxItemWidth : 132px;
|
|
||||||
dt{
|
|
||||||
float : left;
|
|
||||||
clear : left;
|
|
||||||
width : @maxItemWidth;
|
|
||||||
text-align : right;
|
|
||||||
&::after {
|
|
||||||
content: " : ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dd{
|
|
||||||
margin : 0 0 0 @maxItemWidth + 10px;
|
|
||||||
padding : 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./brewRenderer.less');
|
require('./brewRenderer.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const { useState, useRef, useEffect, useCallback } = React;
|
const { useState, useRef, useCallback } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
||||||
@@ -64,7 +64,6 @@ const BrewRenderer = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
height : PAGE_HEIGHT,
|
|
||||||
isMounted : false,
|
isMounted : false,
|
||||||
visibility : 'hidden',
|
visibility : 'hidden',
|
||||||
zoom : 100
|
zoom : 100
|
||||||
@@ -78,17 +77,6 @@ const BrewRenderer = (props)=>{
|
|||||||
rawPages = props.text.split(/^\\page$/gm);
|
rawPages = props.text.split(/^\\page$/gm);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(()=>{ // Unmounting steps
|
|
||||||
return ()=>{window.removeEventListener('resize', updateSize);};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const updateSize = ()=>{
|
|
||||||
setState((prevState)=>({
|
|
||||||
...prevState,
|
|
||||||
height : mainRef.current.parentNode.clientHeight,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateCurrentPage = useCallback(_.throttle((e)=>{
|
const updateCurrentPage = useCallback(_.throttle((e)=>{
|
||||||
const { scrollTop, clientHeight, scrollHeight } = e.target;
|
const { scrollTop, clientHeight, scrollHeight } = e.target;
|
||||||
const totalScrollableHeight = scrollHeight - clientHeight;
|
const totalScrollableHeight = scrollHeight - clientHeight;
|
||||||
@@ -163,8 +151,6 @@ const BrewRenderer = (props)=>{
|
|||||||
|
|
||||||
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
||||||
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
||||||
updateSize();
|
|
||||||
window.addEventListener('resize', updateSize);
|
|
||||||
renderPages(); //Make sure page is renderable before showing
|
renderPages(); //Make sure page is renderable before showing
|
||||||
setState((prevState)=>({
|
setState((prevState)=>({
|
||||||
...prevState,
|
...prevState,
|
||||||
@@ -187,6 +173,12 @@ const BrewRenderer = (props)=>{
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const styleObject = {};
|
||||||
|
|
||||||
|
if(global.config.deployment) {
|
||||||
|
styleObject.backgroundImage = `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='40px' width='200px'><text x='0' y='15' fill='white' font-size='20'>${global.config.deployment}</text></svg>")`;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/*render dummy page while iFrame is mounting.*/}
|
{/*render dummy page while iFrame is mounting.*/}
|
||||||
@@ -212,11 +204,11 @@ const BrewRenderer = (props)=>{
|
|||||||
contentDidMount={frameDidMount}
|
contentDidMount={frameDidMount}
|
||||||
onClick={()=>{emitClick();}}
|
onClick={()=>{emitClick();}}
|
||||||
>
|
>
|
||||||
<div className={'brewRenderer'}
|
<div className={`brewRenderer ${global.config.deployment && 'deployment'}`}
|
||||||
onScroll={updateCurrentPage}
|
onScroll={updateCurrentPage}
|
||||||
onKeyDown={handleControlKeys}
|
onKeyDown={handleControlKeys}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
style={{ height: state.height }}>
|
style={ styleObject }>
|
||||||
|
|
||||||
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
||||||
{state.isMounted
|
{state.isMounted
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
overflow-y : scroll;
|
overflow-y : scroll;
|
||||||
will-change : transform;
|
will-change : transform;
|
||||||
padding-top : 30px;
|
padding-top : 30px;
|
||||||
|
height : 100vh;
|
||||||
|
&.deployment {
|
||||||
|
background-color: darkred;
|
||||||
|
}
|
||||||
:where(.pages) {
|
:where(.pages) {
|
||||||
margin : 30px 0px;
|
margin : 30px 0px;
|
||||||
& > :where(.page) {
|
& > :where(.page) {
|
||||||
@@ -39,6 +43,7 @@
|
|||||||
overflow-y : unset;
|
overflow-y : unset;
|
||||||
.pages {
|
.pages {
|
||||||
margin : 0px;
|
margin : 0px;
|
||||||
|
zoom: 100% !important;
|
||||||
& > .page { box-shadow : unset; }
|
& > .page { box-shadow : unset; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '../../../components/dialog.jsx';
|
||||||
|
|
||||||
const DISMISS_KEY = 'dismiss_notification04-09-24';
|
const DISMISS_KEY = 'dismiss_notification01-10-24';
|
||||||
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
||||||
|
|
||||||
const NotificationPopup = ()=>{
|
const NotificationPopup = ()=>{
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 250, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./snippetbar.less');
|
require('./snippetbar.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
import { getHistoryItems, historyExists } from '../../utils/versionHistory.js';
|
import { loadHistory } from '../../utils/versionHistory.js';
|
||||||
|
|
||||||
//Import all themes
|
//Import all themes
|
||||||
const ThemeSnippets = {};
|
const ThemeSnippets = {};
|
||||||
@@ -50,30 +50,47 @@ const Snippetbar = createClass({
|
|||||||
renderer : this.props.renderer,
|
renderer : this.props.renderer,
|
||||||
themeSelector : false,
|
themeSelector : false,
|
||||||
snippets : [],
|
snippets : [],
|
||||||
historyExists : false
|
showHistory : false,
|
||||||
|
historyExists : false,
|
||||||
|
historyItems : []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount : async function() {
|
componentDidMount : async function(prevState) {
|
||||||
const snippets = this.compileSnippets();
|
const snippets = this.compileSnippets();
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : snippets
|
snippets : snippets
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate : async function(prevProps) {
|
componentDidUpdate : async function(prevProps, prevState) {
|
||||||
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) {
|
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) {
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : this.compileSnippets()
|
snippets : this.compileSnippets()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if(historyExists(this.props.brew) != this.state.historyExists){
|
// Update history list if it has changed
|
||||||
this.setState({
|
const checkHistoryItems = await loadHistory(this.props.brew);
|
||||||
historyExists : !this.state.historyExists
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// If all items have the noData property, there is no saved data
|
||||||
|
const checkHistoryExists = !checkHistoryItems.every((historyItem)=>{
|
||||||
|
return historyItem?.noData;
|
||||||
|
});
|
||||||
|
if(prevState.historyExists != checkHistoryExists){
|
||||||
|
this.setState({
|
||||||
|
historyExists : checkHistoryExists
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If any history items have changed, update the list
|
||||||
|
if(checkHistoryExists && checkHistoryItems.some((historyItem, index)=>{
|
||||||
|
return index >= prevState.historyItems.length || !_.isEqual(historyItem, prevState.historyItems[index]);
|
||||||
|
})){
|
||||||
|
this.setState({
|
||||||
|
historyItems : checkHistoryItems
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mergeCustomizer : function(oldValue, newValue, key) {
|
mergeCustomizer : function(oldValue, newValue, key) {
|
||||||
@@ -151,12 +168,18 @@ const Snippetbar = createClass({
|
|||||||
return this.props.updateBrew(item);
|
return this.props.updateBrew(item);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggleHistoryMenu : function(){
|
||||||
|
this.setState({
|
||||||
|
showHistory : !this.state.showHistory
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
renderHistoryItems : function() {
|
renderHistoryItems : function() {
|
||||||
const historyItems = getHistoryItems(this.props.brew);
|
if(!this.state.historyExists) return;
|
||||||
|
|
||||||
return <div className='dropdown'>
|
return <div className='dropdown'>
|
||||||
{_.map(historyItems, (item, index)=>{
|
{_.map(this.state.historyItems, (item, index)=>{
|
||||||
if(!item.savedAt) return;
|
if(item.noData || !item.savedAt) return;
|
||||||
|
|
||||||
const saveTime = new Date(item.savedAt);
|
const saveTime = new Date(item.savedAt);
|
||||||
const diffMs = new Date() - saveTime;
|
const diffMs = new Date() - saveTime;
|
||||||
@@ -197,9 +220,10 @@ const Snippetbar = createClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <div className='editors'>
|
return <div className='editors'>
|
||||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`} >
|
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
||||||
|
onClick={this.toggleHistoryMenu} >
|
||||||
<i className='fas fa-clock-rotate-left' />
|
<i className='fas fa-clock-rotate-left' />
|
||||||
{this.state.historyExists && this.renderHistoryItems() }
|
{ this.state.showHistory && this.renderHistoryItems() }
|
||||||
</div>
|
</div>
|
||||||
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
||||||
onClick={this.props.undo} >
|
onClick={this.props.undo} >
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const cx = require('classnames');
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const MAX_TITLE_LENGTH = 50;
|
|
||||||
|
|
||||||
|
|
||||||
const EditTitle = createClass({
|
|
||||||
displayName : 'EditTitleNavItem',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
title : '',
|
|
||||||
onChange : function(){}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
handleChange : function(e){
|
|
||||||
if(e.target.value.length > MAX_TITLE_LENGTH) return;
|
|
||||||
this.props.onChange(e.target.value);
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
return <Nav.item className='editTitle'>
|
|
||||||
<input placeholder='Brew Title' type='text' value={this.props.title} onChange={this.handleChange} />
|
|
||||||
|
|
||||||
<div className={cx('charCount', { 'max': this.props.title.length >= MAX_TITLE_LENGTH })}>
|
|
||||||
{this.props.title.length}/{MAX_TITLE_LENGTH}
|
|
||||||
</div>
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = EditTitle;
|
|
||||||
@@ -36,7 +36,7 @@ const RecentItems = createClass({
|
|||||||
//== Add current brew to appropriate recent items list (depending on storageKey) ==//
|
//== Add current brew to appropriate recent items list (depending on storageKey) ==//
|
||||||
if(this.props.storageKey == 'edit'){
|
if(this.props.storageKey == 'edit'){
|
||||||
let editId = this.props.brew.editId;
|
let editId = this.props.brew.editId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
||||||
}
|
}
|
||||||
edited = _.filter(edited, (brew)=>{
|
edited = _.filter(edited, (brew)=>{
|
||||||
@@ -51,7 +51,7 @@ const RecentItems = createClass({
|
|||||||
}
|
}
|
||||||
if(this.props.storageKey == 'view'){
|
if(this.props.storageKey == 'view'){
|
||||||
let shareId = this.props.brew.shareId;
|
let shareId = this.props.brew.shareId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
shareId = `${this.props.brew.googleId}${this.props.brew.shareId}`;
|
shareId = `${this.props.brew.googleId}${this.props.brew.shareId}`;
|
||||||
}
|
}
|
||||||
viewed = _.filter(viewed, (brew)=>{
|
viewed = _.filter(viewed, (brew)=>{
|
||||||
@@ -83,7 +83,7 @@ const RecentItems = createClass({
|
|||||||
let edited = JSON.parse(localStorage.getItem(EDIT_KEY) || '[]');
|
let edited = JSON.parse(localStorage.getItem(EDIT_KEY) || '[]');
|
||||||
if(this.props.storageKey == 'edit') {
|
if(this.props.storageKey == 'edit') {
|
||||||
let prevEditId = prevProps.brew.editId;
|
let prevEditId = prevProps.brew.editId;
|
||||||
if(prevProps.brew.googleId){
|
if(prevProps.brew.googleId && !this.props.brew.stubbed){
|
||||||
prevEditId = `${prevProps.brew.googleId}${prevProps.brew.editId}`;
|
prevEditId = `${prevProps.brew.googleId}${prevProps.brew.editId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ const RecentItems = createClass({
|
|||||||
return brew.id !== prevEditId;
|
return brew.id !== prevEditId;
|
||||||
});
|
});
|
||||||
let editId = this.props.brew.editId;
|
let editId = this.props.brew.editId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
||||||
}
|
}
|
||||||
edited.unshift({
|
edited.unshift({
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const MAIN_URL = 'https://www.reddit.com/r/UnearthedArcana/submit?selftext=true';
|
|
||||||
|
|
||||||
|
|
||||||
const RedditShare = createClass({
|
|
||||||
displayName : 'RedditShareNavItem',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
brew : {
|
|
||||||
title : '',
|
|
||||||
sharedId : '',
|
|
||||||
text : ''
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getText : function(){
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
handleClick : function(){
|
|
||||||
const url = [
|
|
||||||
MAIN_URL,
|
|
||||||
`title=${encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!')}`,
|
|
||||||
`text=${encodeURIComponent(this.props.brew.text)}`
|
|
||||||
].join('&');
|
|
||||||
|
|
||||||
window.open(url, '_blank');
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
|
|
||||||
share on reddit
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = RedditShare;
|
|
||||||
@@ -228,8 +228,8 @@ const EditPage = createClass({
|
|||||||
htmlErrors : Markdown.validate(prevState.brew.text)
|
htmlErrors : Markdown.validate(prevState.brew.text)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateHistory(this.state.brew);
|
await updateHistory(this.state.brew);
|
||||||
versionHistoryGarbageCollection();
|
await versionHistoryGarbageCollection();
|
||||||
|
|
||||||
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
|
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
|
||||||
|
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ const errorIndex = (props)=>{
|
|||||||
|
|
||||||
**Brew Title:** ${props.brew.brewTitle}`,
|
**Brew Title:** ${props.brew.brewTitle}`,
|
||||||
|
|
||||||
|
// ####### Admin page error #######
|
||||||
|
'52': dedent`
|
||||||
|
## Access Denied
|
||||||
|
You need to provide correct administrator credentials to access this page.`,
|
||||||
|
|
||||||
'90' : dedent` An unexpected error occurred while looking for these brews.
|
'90' : dedent` An unexpected error occurred while looking for these brews.
|
||||||
Try again in a few minutes.`,
|
Try again in a few minutes.`,
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ const SharePage = createClass({
|
|||||||
<BrewRenderer
|
<BrewRenderer
|
||||||
text={this.props.brew.text}
|
text={this.props.brew.text}
|
||||||
style={this.props.brew.style}
|
style={this.props.brew.style}
|
||||||
|
lang={this.props.brew.lang}
|
||||||
renderer={this.props.brew.renderer}
|
renderer={this.props.brew.renderer}
|
||||||
theme={this.props.brew.theme}
|
theme={this.props.brew.theme}
|
||||||
themeBundle={this.state.themeBundle}
|
themeBundle={this.state.themeBundle}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import * as IDB from 'idb-keyval/dist/index.js';
|
||||||
|
|
||||||
export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY';
|
export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY';
|
||||||
export const HISTORY_SLOTS = 5;
|
export const HISTORY_SLOTS = 5;
|
||||||
|
|
||||||
// History values in minutes
|
// History values in minutes
|
||||||
const DEFAULT_HISTORY_SAVE_DELAYS = {
|
const HISTORY_SAVE_DELAYS = {
|
||||||
'0' : 0,
|
'0' : 0,
|
||||||
'1' : 2,
|
'1' : 2,
|
||||||
'2' : 10,
|
'2' : 10,
|
||||||
@@ -10,29 +12,30 @@ const DEFAULT_HISTORY_SAVE_DELAYS = {
|
|||||||
'4' : 12 * 60,
|
'4' : 12 * 60,
|
||||||
'5' : 2 * 24 * 60
|
'5' : 2 * 24 * 60
|
||||||
};
|
};
|
||||||
|
// const HISTORY_SAVE_DELAYS = {
|
||||||
|
// '0' : 0,
|
||||||
|
// '1' : 1,
|
||||||
|
// '2' : 2,
|
||||||
|
// '3' : 3,
|
||||||
|
// '4' : 4,
|
||||||
|
// '5' : 5
|
||||||
|
// };
|
||||||
|
|
||||||
const DEFAULT_GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
const HB_DB = 'HOMEBREWERY-DB';
|
||||||
|
const HB_STORE = 'HISTORY';
|
||||||
const HISTORY_SAVE_DELAYS = global.config?.historyData?.HISTORY_SAVE_DELAYS ?? DEFAULT_HISTORY_SAVE_DELAYS;
|
|
||||||
const GARBAGE_COLLECT_DELAY = global.config?.historyData?.GARBAGE_COLLECT_DELAY ?? DEFAULT_GARBAGE_COLLECT_DELAY;
|
|
||||||
|
|
||||||
|
const GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
||||||
|
// const GARBAGE_COLLECT_DELAY = 10;
|
||||||
|
|
||||||
|
|
||||||
function getKeyBySlot(brew, slot){
|
function getKeyBySlot(brew, slot){
|
||||||
|
// Return a string representing the key for this brew and history slot
|
||||||
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getVersionBySlot(brew, slot){
|
function parseBrewForStorage(brew, slot = 0) {
|
||||||
// Read stored brew data
|
// Strip out unneeded object properties
|
||||||
// - If it exists, parse data to object
|
// Returns an array of [ key, brew ]
|
||||||
// - If it doesn't exist, pass default object
|
|
||||||
const key = getKeyBySlot(brew, slot);
|
|
||||||
const storedVersion = localStorage.getItem(key);
|
|
||||||
const output = storedVersion ? JSON.parse(storedVersion) : { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
function updateStoredBrew(brew, slot = 0) {
|
|
||||||
const archiveBrew = {
|
const archiveBrew = {
|
||||||
title : brew.title,
|
title : brew.title,
|
||||||
text : brew.text,
|
text : brew.text,
|
||||||
@@ -46,44 +49,55 @@ function updateStoredBrew(brew, slot = 0) {
|
|||||||
archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]);
|
archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]);
|
||||||
|
|
||||||
const key = getKeyBySlot(brew, slot);
|
const key = getKeyBySlot(brew, slot);
|
||||||
localStorage.setItem(key, JSON.stringify(archiveBrew));
|
|
||||||
|
return [key, archiveBrew];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a custom IDB store
|
||||||
export function historyExists(brew){
|
async function createHBStore(){
|
||||||
return Object.keys(localStorage)
|
return await IDB.createStore(HB_DB, HB_STORE);
|
||||||
.some((key)=>{
|
|
||||||
return key.startsWith(`${HISTORY_PREFIX}-${brew.shareId}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadHistory(brew){
|
export async function loadHistory(brew){
|
||||||
const history = {};
|
const DEFAULT_HISTORY_ITEM = { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
||||||
|
|
||||||
// Load data from local storage to History object
|
const historyKeys = [];
|
||||||
|
|
||||||
|
// Create array of all history keys
|
||||||
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
||||||
history[i] = getVersionBySlot(brew, i);
|
historyKeys.push(getKeyBySlot(brew, i));
|
||||||
};
|
};
|
||||||
|
|
||||||
return history;
|
// Load all keys from IDB at once
|
||||||
|
const dataArray = await IDB.getMany(historyKeys, await createHBStore());
|
||||||
|
return dataArray.map((data)=>{ return data ?? DEFAULT_HISTORY_ITEM; });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateHistory(brew) {
|
export async function updateHistory(brew) {
|
||||||
const history = loadHistory(brew);
|
const history = await loadHistory(brew);
|
||||||
|
|
||||||
// Walk each version position
|
// Walk each version position
|
||||||
for (let slot = HISTORY_SLOTS; slot > 0; slot--){
|
for (let slot = HISTORY_SLOTS - 1; slot >= 0; slot--){
|
||||||
const storedVersion = history[slot];
|
const storedVersion = history[slot];
|
||||||
|
|
||||||
// If slot has expired, update all lower slots and break
|
// If slot has expired, update all lower slots and break
|
||||||
if(new Date() >= new Date(storedVersion.expireAt)){
|
if(new Date() >= new Date(storedVersion.expireAt)){
|
||||||
for (let updateSlot = slot - 1; updateSlot>0; updateSlot--){
|
|
||||||
|
// Create array of arrays : [ [key1, value1], [key2, value2], ..., [keyN, valueN] ]
|
||||||
|
// to pass to IDB.setMany
|
||||||
|
const historyUpdate = [];
|
||||||
|
|
||||||
|
for (let updateSlot = slot; updateSlot > 0; updateSlot--){
|
||||||
// Move data from updateSlot to updateSlot + 1
|
// Move data from updateSlot to updateSlot + 1
|
||||||
!history[updateSlot]?.noData && updateStoredBrew(history[updateSlot], updateSlot + 1);
|
if(!history[updateSlot - 1]?.noData) {
|
||||||
|
historyUpdate.push(parseBrewForStorage(history[updateSlot - 1], updateSlot + 1));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the most recent brew
|
// Update the most recent brew
|
||||||
updateStoredBrew(brew, 1);
|
historyUpdate.push(parseBrewForStorage(brew, 1));
|
||||||
|
|
||||||
|
await IDB.setMany(historyUpdate, await createHBStore());
|
||||||
|
|
||||||
// Break out of data checks because we found an expired value
|
// Break out of data checks because we found an expired value
|
||||||
break;
|
break;
|
||||||
@@ -91,26 +105,15 @@ export function updateHistory(brew) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getHistoryItems(brew){
|
export async function versionHistoryGarbageCollection(){
|
||||||
const historyArray = [];
|
|
||||||
|
|
||||||
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
const entries = await IDB.entries(await createHBStore());
|
||||||
historyArray.push(getVersionBySlot(brew, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return historyArray;
|
for (const [key, value] of entries){
|
||||||
|
const expireAt = new Date(value.savedAt);
|
||||||
|
expireAt.setMinutes(expireAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
||||||
|
if(new Date() > expireAt){
|
||||||
|
await IDB.del(key, await createHBStore());
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function versionHistoryGarbageCollection(){
|
|
||||||
Object.keys(localStorage)
|
|
||||||
.filter((key)=>{
|
|
||||||
return key.startsWith(HISTORY_PREFIX);
|
|
||||||
})
|
|
||||||
.forEach((key)=>{
|
|
||||||
const collectAt = new Date(JSON.parse(localStorage.getItem(key)).savedAt);
|
|
||||||
collectAt.setMinutes(collectAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
|
||||||
if(new Date() > collectAt){
|
|
||||||
localStorage.removeItem(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
@@ -6,5 +6,7 @@
|
|||||||
"enable_v3" : true,
|
"enable_v3" : true,
|
||||||
"enable_themes" : true,
|
"enable_themes" : true,
|
||||||
"local_environments" : ["docker", "local"],
|
"local_environments" : ["docker", "local"],
|
||||||
"publicUrl" : "https://homebrewery.naturalcrit.com"
|
"publicUrl" : "https://homebrewery.naturalcrit.com",
|
||||||
|
"hb_images" : null,
|
||||||
|
"hb_fonts" : null
|
||||||
}
|
}
|
||||||
|
|||||||
1500
package-lock.json
generated
1500
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@@ -4,17 +4,17 @@
|
|||||||
"version": "3.15.0",
|
"version": "3.15.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": "^10.2.x",
|
"npm": "^10.2.x",
|
||||||
"node": "^20.8.x"
|
"node": "^20.17.x"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/naturalcrit/homebrewery.git"
|
"url": "git://github.com/naturalcrit/homebrewery.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node --experimental-require-module scripts/dev.js",
|
||||||
"quick": "node scripts/quick.js",
|
"quick": "node --experimental-require-module scripts/quick.js",
|
||||||
"build": "node scripts/buildHomebrew.js && node scripts/buildAdmin.js",
|
"build": "node --experimental-require-module scripts/buildHomebrew.js && node --experimental-require-module scripts/buildAdmin.js",
|
||||||
"builddev": "node scripts/buildHomebrew.js --dev",
|
"builddev": "node --experimental-require-module scripts/buildHomebrew.js --dev",
|
||||||
"lint": "eslint --fix",
|
"lint": "eslint --fix",
|
||||||
"lint:dry": "eslint",
|
"lint:dry": "eslint",
|
||||||
"stylelint": "stylelint --fix **/*.{less}",
|
"stylelint": "stylelint --fix **/*.{less}",
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
||||||
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
||||||
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
||||||
|
"test:api-unit:notifications": "jest \"server/.*.spec.js\" -t \"Notifications\" --verbose",
|
||||||
"test:coverage": "jest --coverage --silent --runInBand",
|
"test:coverage": "jest --coverage --silent --runInBand",
|
||||||
"test:dev": "jest --verbose --watch",
|
"test:dev": "jest --verbose --watch",
|
||||||
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
||||||
@@ -37,10 +38,10 @@
|
|||||||
"test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace",
|
"test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace",
|
||||||
"test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace",
|
"test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace",
|
||||||
"test:route": "jest tests/routes/static-pages.test.js --verbose",
|
"test:route": "jest tests/routes/static-pages.test.js --verbose",
|
||||||
"phb": "node scripts/phb.js",
|
"phb": "node --experimental-require-module scripts/phb.js",
|
||||||
"prod": "set NODE_ENV=production && npm run build",
|
"prod": "set NODE_ENV=production && npm run build",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"start": "node server.js"
|
"start": "node --experimental-require-module server.js"
|
||||||
},
|
},
|
||||||
"author": "stolksdorf",
|
"author": "stolksdorf",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -85,23 +86,24 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.25.2",
|
"@babel/core": "^7.25.8",
|
||||||
"@babel/plugin-transform-runtime": "^7.25.4",
|
"@babel/plugin-transform-runtime": "^7.25.7",
|
||||||
"@babel/preset-env": "^7.25.4",
|
"@babel/preset-env": "^7.25.8",
|
||||||
"@babel/preset-react": "^7.24.7",
|
"@babel/preset-react": "^7.25.7",
|
||||||
"@googleapis/drive": "^8.14.0",
|
"@googleapis/drive": "^8.14.0",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"codemirror": "^5.65.6",
|
"codemirror": "^5.65.6",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.7",
|
||||||
"create-react-class": "^15.7.0",
|
"create-react-class": "^15.7.0",
|
||||||
"dedent-tabs": "^0.10.3",
|
"dedent-tabs": "^0.10.3",
|
||||||
"dompurify": "^3.1.7",
|
"dompurify": "^3.1.7",
|
||||||
"expr-eval": "^2.0.2",
|
"expr-eval": "^2.0.2",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.1",
|
||||||
"express-async-handler": "^1.2.0",
|
"express-async-handler": "^1.2.0",
|
||||||
"express-static-gzip": "2.1.8",
|
"express-static-gzip": "2.1.8",
|
||||||
"fs-extra": "11.2.0",
|
"fs-extra": "11.2.0",
|
||||||
|
"idb-keyval": "^6.2.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jwt-simple": "^0.5.6",
|
"jwt-simple": "^0.5.6",
|
||||||
"less": "^3.13.1",
|
"less": "^3.13.1",
|
||||||
@@ -113,7 +115,7 @@
|
|||||||
"marked-smartypants-lite": "^1.0.2",
|
"marked-smartypants-lite": "^1.0.2",
|
||||||
"markedLegacy": "npm:marked@^0.3.19",
|
"markedLegacy": "npm:marked@^0.3.19",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"mongoose": "^8.7.0",
|
"mongoose": "^8.7.1",
|
||||||
"nanoid": "3.3.4",
|
"nanoid": "3.3.4",
|
||||||
"nconf": "^0.12.1",
|
"nconf": "^0.12.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
@@ -125,11 +127,11 @@
|
|||||||
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git"
|
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@stylistic/stylelint-plugin": "^3.1.0",
|
"@stylistic/stylelint-plugin": "^3.1.1",
|
||||||
"eslint": "^9.11.1",
|
"eslint": "^9.12.0",
|
||||||
"eslint-plugin-jest": "^28.8.3",
|
"eslint-plugin-jest": "^28.8.3",
|
||||||
"eslint-plugin-react": "^7.36.1",
|
"eslint-plugin-react": "^7.37.1",
|
||||||
"globals": "^15.9.0",
|
"globals": "^15.11.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-expect-message": "^1.1.3",
|
"jest-expect-message": "^1.1.3",
|
||||||
"postcss-less": "^6.0.0",
|
"postcss-less": "^6.0.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
const HomebrewModel = require('./homebrew.model.js').model;
|
||||||
|
const NotificationModel = require('./notifications.model.js').model;
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const Moment = require('moment');
|
const Moment = require('moment');
|
||||||
//const render = require('vitreum/steps/render');
|
|
||||||
const templateFn = require('../client/template.js');
|
const templateFn = require('../client/template.js');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ const mw = {
|
|||||||
if(process.env.ADMIN_USER === username && process.env.ADMIN_PASS === password){
|
if(process.env.ADMIN_USER === username && process.env.ADMIN_PASS === password){
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
return res.status(401).send('Access denied');
|
throw { HBErrorCode: '52', code: 401, message: 'Access denied' };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,12 +138,48 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ####################### NOTIFICATIONS
|
||||||
|
|
||||||
|
router.get('/admin/notification/all', async (req, res, next)=>{
|
||||||
|
try {
|
||||||
|
const notifications = await NotificationModel.getAll();
|
||||||
|
return res.json(notifications);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error getting all notifications: ', error.message);
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{
|
||||||
|
console.table(req.body);
|
||||||
|
try {
|
||||||
|
const notification = await NotificationModel.addNotification(req.body);
|
||||||
|
return res.status(201).json(notification);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error adding notification: ', error.message);
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, next)=>{
|
||||||
|
try {
|
||||||
|
const notification = await NotificationModel.deleteNotification(req.params.id);
|
||||||
|
return res.json(notification);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting notification: { key: ', req.params.id, ' error: ', error.message, ' }');
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/admin', mw.adminOnly, (req, res)=>{
|
router.get('/admin', mw.adminOnly, (req, res)=>{
|
||||||
templateFn('admin', {
|
templateFn('admin', {
|
||||||
url : req.originalUrl
|
url : req.originalUrl
|
||||||
})
|
})
|
||||||
.then((page)=>res.send(page))
|
.then((page)=>res.send(page))
|
||||||
.catch((err)=>res.sendStatus(500));
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
res.sendStatus(500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
116
server/admin.api.spec.js
Normal file
116
server/admin.api.spec.js
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
const supertest = require('supertest');
|
||||||
|
|
||||||
|
const app = supertest.agent(require('app.js').app)
|
||||||
|
.set('X-Forwarded-Proto', 'https');
|
||||||
|
|
||||||
|
const NotificationModel = require('./notifications.model.js').model;
|
||||||
|
|
||||||
|
describe('Tests for admin api', ()=>{
|
||||||
|
afterEach(()=>{
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Notifications', ()=>{
|
||||||
|
it('should return list of all notifications', async ()=>{
|
||||||
|
const testNotifications = ['a', 'b'];
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'find')
|
||||||
|
.mockImplementationOnce(() => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue(testNotifications) };
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.get('/admin/notification/all')
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual(testNotifications);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add a new notification', async ()=>{
|
||||||
|
const inputNotification = {
|
||||||
|
title : 'Test Notification',
|
||||||
|
text : 'This is a test notification',
|
||||||
|
startAt : new Date().toISOString(),
|
||||||
|
stopAt : new Date().toISOString(),
|
||||||
|
dismissKey : 'testKey'
|
||||||
|
};
|
||||||
|
|
||||||
|
const savedNotification = {
|
||||||
|
...inputNotification,
|
||||||
|
_id : expect.any(String),
|
||||||
|
createdAt : expect.any(String),
|
||||||
|
startAt : inputNotification.startAt,
|
||||||
|
stopAt : inputNotification.stopAt,
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel.prototype, 'save')
|
||||||
|
.mockImplementationOnce(function() {
|
||||||
|
return Promise.resolve(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.post('/admin/notification/add')
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`)
|
||||||
|
.send(inputNotification);
|
||||||
|
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
expect(response.body).toEqual(savedNotification);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle error adding a notification without dismissKey', async () => {
|
||||||
|
const inputNotification = {
|
||||||
|
title : 'Test Notification',
|
||||||
|
text : 'This is a test notification',
|
||||||
|
startAt : new Date().toISOString(),
|
||||||
|
stopAt : new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
//Change 'save' function to just return itself instead of actually interacting with the database
|
||||||
|
jest.spyOn(NotificationModel.prototype, 'save')
|
||||||
|
.mockImplementationOnce(function() {
|
||||||
|
return Promise.resolve(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.post('/admin/notification/add')
|
||||||
|
.set('Authorization', 'Basic ' + Buffer.from('admin:password3').toString('base64'))
|
||||||
|
.send(inputNotification);
|
||||||
|
|
||||||
|
expect(response.status).toBe(500);
|
||||||
|
expect(response.body).toEqual({ message: 'Dismiss key is required!' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete a notification based on its dismiss key', async ()=>{
|
||||||
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'findOneAndDelete')
|
||||||
|
.mockImplementationOnce((key) => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue(key) };
|
||||||
|
});
|
||||||
|
const response = await app
|
||||||
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'});
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual({ dismissKey: 'testKey' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle error deleting a notification that doesnt exist', async ()=>{
|
||||||
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'findOneAndDelete')
|
||||||
|
.mockImplementationOnce(() => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue() };
|
||||||
|
});
|
||||||
|
const response = await app
|
||||||
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'});
|
||||||
|
expect(response.status).toBe(500);
|
||||||
|
expect(response.body).toEqual({ message: 'Notification not found' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -8,6 +8,7 @@ const express = require('express');
|
|||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
||||||
const GoogleActions = require('./googleActions.js');
|
const GoogleActions = require('./googleActions.js');
|
||||||
@@ -30,6 +31,8 @@ const sanitizeBrew = (brew, accessType)=>{
|
|||||||
return brew;
|
return brew;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.set('trust proxy', 1 /* number of proxies between user and server */)
|
||||||
|
|
||||||
app.use('/', serveCompressedStaticAssets(`build`));
|
app.use('/', serveCompressedStaticAssets(`build`));
|
||||||
app.use(require('./middleware/content-negotiation.js'));
|
app.use(require('./middleware/content-negotiation.js'));
|
||||||
app.use(require('body-parser').json({ limit: '25mb' }));
|
app.use(require('body-parser').json({ limit: '25mb' }));
|
||||||
@@ -255,6 +258,8 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
brews.forEach(brew => brew.stubbed = true); //All brews from MongoDB are "stubbed"
|
||||||
|
|
||||||
if(ownAccount && req?.account?.googleId){
|
if(ownAccount && req?.account?.googleId){
|
||||||
const auth = await GoogleActions.authCheck(req.account, res);
|
const auth = await GoogleActions.authCheck(req.account, res);
|
||||||
let googleBrews = await GoogleActions.listGoogleBrews(auth)
|
let googleBrews = await GoogleActions.listGoogleBrews(auth)
|
||||||
@@ -262,12 +267,12 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If stub matches file from Google, use Google metadata over stub metadata
|
||||||
if(googleBrews && googleBrews.length > 0) {
|
if(googleBrews && googleBrews.length > 0) {
|
||||||
for (const brew of brews.filter((brew)=>brew.googleId)) {
|
for (const brew of brews.filter((brew)=>brew.googleId)) {
|
||||||
const match = googleBrews.findIndex((b)=>b.editId === brew.editId);
|
const match = googleBrews.findIndex((b)=>b.editId === brew.editId);
|
||||||
if(match !== -1) {
|
if(match !== -1) {
|
||||||
brew.googleId = googleBrews[match].googleId;
|
brew.googleId = googleBrews[match].googleId;
|
||||||
brew.stubbed = true;
|
|
||||||
brew.pageCount = googleBrews[match].pageCount;
|
brew.pageCount = googleBrews[match].pageCount;
|
||||||
brew.renderer = googleBrews[match].renderer;
|
brew.renderer = googleBrews[match].renderer;
|
||||||
brew.version = googleBrews[match].version;
|
brew.version = googleBrews[match].version;
|
||||||
@@ -276,6 +281,7 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Remaining unstubbed google brews display current user as author
|
||||||
googleBrews = googleBrews.map((brew)=>({ ...brew, authors: [req.account.username] }));
|
googleBrews = googleBrews.map((brew)=>({ ...brew, authors: [req.account.username] }));
|
||||||
brews = _.concat(brews, googleBrews);
|
brews = _.concat(brews, googleBrews);
|
||||||
}
|
}
|
||||||
@@ -392,22 +398,12 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
let googleCount = [];
|
let googleCount = [];
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
if(req.account.googleId) {
|
if(req.account.googleId) {
|
||||||
try {
|
auth = await GoogleActions.authCheck(req.account, res, false)
|
||||||
auth = await GoogleActions.authCheck(req.account, res, false);
|
|
||||||
} catch (e) {
|
googleCount = await GoogleActions.listGoogleBrews(auth)
|
||||||
auth = undefined;
|
.catch((err)=>{
|
||||||
console.log('Google auth check failed!');
|
console.error(err);
|
||||||
console.log(e);
|
});
|
||||||
}
|
|
||||||
if(auth.credentials.access_token) {
|
|
||||||
try {
|
|
||||||
googleCount = await GoogleActions.listGoogleBrews(auth);
|
|
||||||
} catch (e) {
|
|
||||||
googleCount = undefined;
|
|
||||||
console.log('List Google files failed!');
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = { authors: req.account.username, googleId: { $exists: false } };
|
const query = { authors: req.account.username, googleId: { $exists: false } };
|
||||||
@@ -421,7 +417,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
username : req.account.username,
|
username : req.account.username,
|
||||||
issued : req.account.issued,
|
issued : req.account.issued,
|
||||||
googleId : Boolean(req.account.googleId),
|
googleId : Boolean(req.account.googleId),
|
||||||
authCheck : Boolean(req.account.googleId && auth.credentials.access_token),
|
authCheck : Boolean(req.account.googleId && auth?.credentials.access_token),
|
||||||
mongoCount : mongoCount,
|
mongoCount : mongoCount,
|
||||||
googleCount : googleCount?.length
|
googleCount : googleCount?.length
|
||||||
};
|
};
|
||||||
@@ -451,6 +447,10 @@ if(isLocalEnvironment){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Static Local Paths
|
||||||
|
app.use('/staticImages', express.static(config.get('hb_images') && fs.existsSync(config.get('hb_images')) ? config.get('hb_images') :'staticImages'));
|
||||||
|
app.use('/staticFonts', express.static(config.get('hb_fonts') && fs.existsSync(config.get('hb_fonts')) ? config.get('hb_fonts'):'staticFonts'));
|
||||||
|
|
||||||
//Vault Page
|
//Vault Page
|
||||||
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
||||||
req.ogMeta = { ...defaultMetaTags,
|
req.ogMeta = { ...defaultMetaTags,
|
||||||
@@ -476,7 +476,7 @@ const renderPage = async (req, res)=>{
|
|||||||
local : isLocalEnvironment,
|
local : isLocalEnvironment,
|
||||||
publicUrl : config.get('publicUrl') ?? '',
|
publicUrl : config.get('publicUrl') ?? '',
|
||||||
environment : nodeEnv,
|
environment : nodeEnv,
|
||||||
history : config.get('historyConfig') ?? {}
|
deployment : config.get('heroku_app_name') ?? ''
|
||||||
};
|
};
|
||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : require('./../package.json').version,
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ if(!config.get('service_account')){
|
|||||||
|
|
||||||
const defaultAuth = serviceAuth || config.get('google_api_key');
|
const defaultAuth = serviceAuth || config.get('google_api_key');
|
||||||
|
|
||||||
|
const retryConfig = {
|
||||||
|
retry: 3, // Number of retry attempts
|
||||||
|
retryDelay: 100, // Initial delay in milliseconds
|
||||||
|
retryDelayMultiplier: 2, // Multiplier for exponential backoff
|
||||||
|
maxRetryDelay: 32000, // Maximum delay in milliseconds
|
||||||
|
httpMethodsToRetry: ['PATCH'], // Only retry PATCH requests
|
||||||
|
statusCodesToRetry: [[429, 429]], // Only retry on 429 status code
|
||||||
|
};
|
||||||
|
|
||||||
const GoogleActions = {
|
const GoogleActions = {
|
||||||
|
|
||||||
authCheck : (account, res, updateTokens=true)=>{
|
authCheck : (account, res, updateTokens=true)=>{
|
||||||
@@ -112,9 +121,7 @@ const GoogleActions = {
|
|||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log(`Error Listing Google Brews`);
|
console.log(`Error Listing Google Brews`);
|
||||||
console.error(err);
|
|
||||||
throw (err);
|
throw (err);
|
||||||
//TODO: Should break out here, but continues on for some reason.
|
|
||||||
});
|
});
|
||||||
fileList.push(...obj.data.files);
|
fileList.push(...obj.data.files);
|
||||||
NextPageToken = obj.data.nextPageToken;
|
NextPageToken = obj.data.nextPageToken;
|
||||||
@@ -147,8 +154,9 @@ const GoogleActions = {
|
|||||||
return brews;
|
return brews;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateGoogleBrew : async (brew)=>{
|
updateGoogleBrew : async (brew, auth = defaultAuth, userIp)=>{
|
||||||
const drive = googleDrive.drive({ version: 'v3', auth: defaultAuth });
|
const drive = googleDrive.drive({ version: 'v3', auth: auth });
|
||||||
|
console.log(auth == defaultAuth ? 'UPDATE w SERVICEACC' : 'UPDATE w USERACC')
|
||||||
|
|
||||||
await drive.files.update({
|
await drive.files.update({
|
||||||
fileId : brew.googleId,
|
fileId : brew.googleId,
|
||||||
@@ -168,7 +176,11 @@ const GoogleActions = {
|
|||||||
media : {
|
media : {
|
||||||
mimeType : 'text/plain',
|
mimeType : 'text/plain',
|
||||||
body : brew.text
|
body : brew.text
|
||||||
}
|
},
|
||||||
|
headers: {
|
||||||
|
'X-Forwarded-For': userIp, // Set the X-Forwarded-For header
|
||||||
|
},
|
||||||
|
retryConfig
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log('Error saving to google');
|
console.log('Error saving to google');
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
const config = require('../config.js');
|
||||||
|
const nodeEnv = config.get('node_env');
|
||||||
|
const isLocalEnvironment = config.get('local_environments').includes(nodeEnv);
|
||||||
|
|
||||||
module.exports = (req, res, next)=>{
|
module.exports = (req, res, next)=>{
|
||||||
const isImageRequest = req.get('Accept')?.split(',')
|
const isImageRequest = req.get('Accept')?.split(',')
|
||||||
?.filter((h)=>!h.includes('q='))
|
?.filter((h)=>!h.includes('q='))
|
||||||
?.every((h)=>/image\/.*/.test(h));
|
?.every((h)=>/image\/.*/.test(h));
|
||||||
if(isImageRequest) {
|
if(isImageRequest && !isLocalEnvironment && !req.url?.startsWith('/staticImages')) {
|
||||||
return res.status(406).send({
|
return res.status(406).send({
|
||||||
message : 'Request for image at this URL is not supported'
|
message : 'Request for image at this URL is not supported'
|
||||||
});
|
});
|
||||||
|
|||||||
62
server/notifications.model.js
Normal file
62
server/notifications.model.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
const mongoose = require('mongoose');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const NotificationSchema = new mongoose.Schema({
|
||||||
|
dismissKey : { type: String, unique: true, required: true },
|
||||||
|
title : { type: String, default: '' },
|
||||||
|
text : { type: String, default: '' },
|
||||||
|
createdAt : { type: Date, default: Date.now },
|
||||||
|
startAt : { type: Date, default: Date.now },
|
||||||
|
stopAt : { type: Date, default: Date.now },
|
||||||
|
}, { versionKey: false });
|
||||||
|
|
||||||
|
NotificationSchema.statics.addNotification = async function(data) {
|
||||||
|
if(!data.dismissKey) throw { message: 'Dismiss key is required!' };
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
title : '',
|
||||||
|
text : '',
|
||||||
|
startAt : new Date(),
|
||||||
|
stopAt : new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const notificationData = _.defaults(data, defaults);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newNotification = new this(notificationData);
|
||||||
|
const savedNotification = await newNotification.save();
|
||||||
|
return savedNotification;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error saving notification' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationSchema.statics.deleteNotification = async function(dismissKey) {
|
||||||
|
if(!dismissKey) throw { message: 'Dismiss key is required!' };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec();
|
||||||
|
if(!deletedNotification) {
|
||||||
|
throw { message: 'Notification not found' };
|
||||||
|
}
|
||||||
|
return deletedNotification;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error deleting notification' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationSchema.statics.getAll = async function() {
|
||||||
|
try {
|
||||||
|
const notifications = await this.find().exec();
|
||||||
|
return notifications;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error retrieving notifications' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Notification = mongoose.model('Notification', NotificationSchema);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
schema : NotificationSchema,
|
||||||
|
model : Notification,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user