site updates 2021-04-09
This commit is contained in:
parent
e6555c42b5
commit
7e3b2606f9
15
package-lock.json
generated
15
package-lock.json
generated
@ -2540,6 +2540,12 @@
|
|||||||
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
|
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"clone": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
||||||
|
"integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||||
@ -4834,6 +4840,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz",
|
||||||
"integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg=="
|
"integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg=="
|
||||||
},
|
},
|
||||||
|
"node-cache": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"clone": "2.x"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node-libs-browser": {
|
"node-libs-browser": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz",
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
"@babel/preset-env": "^7.11.0",
|
"@babel/preset-env": "^7.11.0",
|
||||||
"babel-loader": "^8.1.0",
|
"babel-loader": "^8.1.0",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
|
"node-cache": "^5.1.2",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"regenerator-runtime": "^0.13.7",
|
"regenerator-runtime": "^0.13.7",
|
||||||
"sapper": "^0.27.16",
|
"sapper": "^0.27.16",
|
||||||
|
@ -17,6 +17,7 @@ import useragent from 'useragent';
|
|||||||
import RSS from 'rss';
|
import RSS from 'rss';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
import NodeCache from 'node-cache';
|
||||||
import Article from './models/article.js';
|
import Article from './models/article.js';
|
||||||
import Category from './models/category.js';
|
import Category from './models/category.js';
|
||||||
import User from './models/user.js';
|
import User from './models/user.js';
|
||||||
@ -25,6 +26,7 @@ import legacyRouter from './legacy/router.js';
|
|||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const FileStore = sessionFileStore(session);
|
const FileStore = sessionFileStore(session);
|
||||||
|
const cache = new NodeCache();
|
||||||
|
|
||||||
const { PORT, NODE_ENV, SESSION_SECRET, MONGODB_CONN,
|
const { PORT, NODE_ENV, SESSION_SECRET, MONGODB_CONN,
|
||||||
SMTP_USERNAME, SMTP_PASSWORD, SMTP_SERVER, SMTP_PORT, SMTP_RECIPIENTS } = process.env;
|
SMTP_USERNAME, SMTP_PASSWORD, SMTP_SERVER, SMTP_PORT, SMTP_RECIPIENTS } = process.env;
|
||||||
@ -478,7 +480,88 @@ mainRouter
|
|||||||
message: err.message
|
message: err.message
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.get('/api/meet', async function (req, res, next) {
|
||||||
|
if (req.query.token === '1445') {
|
||||||
|
const time = cache.get('lastMeetingTime');
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
LastMeetingTime: time ? time.toJSON() : undefined
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.post('/api/meet', async function (req, res, next) {
|
||||||
|
if (req.body.token === '1445') {
|
||||||
|
const time = new Date();
|
||||||
|
const success = cache.set('lastMeetingTime', time, 3600);
|
||||||
|
if (success) {
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
LastMeetingTime: time.toJSON()
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
res.writeHead(500, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
Error: 'Failed to store meeting time in cache!'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.get('/api/memo', async function (req, res, next) {
|
||||||
|
if (req.query.token === '1445') {
|
||||||
|
const memos = cache.get('memos') || [];
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify(memos));
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.post('/api/memo', async function (req, res, next) {
|
||||||
|
if (req.body.token === '1445') {
|
||||||
|
const memo = req.body.message;
|
||||||
|
if (!memo) {
|
||||||
|
res.writeHead(400, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
Error: 'You must provide a memo message'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
const memos = cache.get('memos') || [];
|
||||||
|
memos.push({
|
||||||
|
Time: new Date(),
|
||||||
|
Message: memo
|
||||||
|
});
|
||||||
|
const success = cache.set('memos', memos);
|
||||||
|
if (success) {
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify(memos));
|
||||||
|
} else {
|
||||||
|
res.writeHead(500, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
Error: 'Failed to store memo in cache!'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.use(helmet())
|
app.use(helmet())
|
||||||
.use(cors())
|
.use(cors())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user