feat: add info endpoint

This commit is contained in:
2023-09-17 07:21:47 +02:00
parent 631904ab3a
commit 0861047442
2 changed files with 30 additions and 5 deletions
+27 -2
View File
@@ -33,7 +33,7 @@ if (resolutions.indexOf(defaultresolution) == -1) {
}
// app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.json( { type: 'application/*+json' }));
app.use(bodyParser.json( { type: 'application/json' }));
app.use(bodyParser.raw( { limit: '10mb', type: 'image/*' }));
app.use(logger('dev'));
@@ -83,7 +83,7 @@ function isAuthenticated(req) {
console.log("got req: ", req);
if (req.headers && req.headers.authorization) {
// console.log("got auth: ", req.headers.authorization);
if (req.headers.authorization == "Basic YXZhdGFyOmphOGNhZmVpOHdhaXBoN0lldmFoR2hhaG5vaDIx") {
if (req.headers.authorization == "Basic YXZhdGFyOmphOGNhZmVpOHdhaXBoN0lldmFoR2hhaG5vaDI=") {
// old global credentials
return true;
} else {
@@ -174,6 +174,31 @@ app.delete('/avatarupload/:jid', async function (req, res) {
}
});
app.post('/avatarupload/info', async function (req, res) {
var ids = req.body.ids;
if (!!ids && typeof ids == "object" && Array.isArray(ids)) {
var result = {};
try {
for (var i = 0; i < ids.length; i++) {
if (ids[i].length == 32) {
const fn = outputDir + "/" + ids[i] + ".jpg";
const fdata = fs.statSync(fn, { throwIfNoEntry: false });
result[ids[i]] = (!!fdata && !!fdata.ctime) ? fdata.ctime.valueOf() : -1;
} else {
result[ids[i]] = -1;
}
}
res.status(200).json(result);
} catch (e) {
console.log("avatarinfo error: ", e);
res.status(500).json(null);
}
} else {
res.status(500).json(null);
}
});
app.get('/avatarupload/health', async function (req, res) {
console.log(moment().format("LTS") + ' health check called');
res.status(200).json({ status: 'OK'});
+3 -3
View File
@@ -603,9 +603,9 @@ safe-buffer@5.2.1, safe-buffer@^5.0.1:
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
semver@^7.3.8:
version "7.5.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e"
integrity sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"