Compare commits
4 Commits
d49a5ae034
...
9d51d4e45e
Author | SHA1 | Date |
---|---|---|
Fred Boniface | 9d51d4e45e | |
Fred Boniface | fde37814a7 | |
Fred Boniface | 8fa0cf775f | |
Fred Boniface | afa4ad7915 |
|
@ -5,7 +5,7 @@ interface versions {
|
||||||
|
|
||||||
const version: versions = {
|
const version: versions = {
|
||||||
api: ["/api/v2"],
|
api: ["/api/v2"],
|
||||||
app: "2024.04.3",
|
app: "2024.04.4",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = version;
|
module.exports = version;
|
||||||
|
|
|
@ -9,7 +9,7 @@ async function getTrain(req, res, next) {
|
||||||
err.status = 401;
|
err.status = 401;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
setCache(res, "private", 180)
|
setCache(res, "private", 240)
|
||||||
let type = req.params.searchType;
|
let type = req.params.searchType;
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
try {
|
try {
|
||||||
|
@ -45,8 +45,14 @@ async function getStation(req, res, next) {
|
||||||
err.status = 401;
|
err.status = 401;
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
setCache(res, "public", 120)
|
const data = await ldb.get(id, true);
|
||||||
res.json(await ldb.get(id, true));
|
// Only cache if data is present
|
||||||
|
if (data.data) {
|
||||||
|
setCache(res, "public", 120);
|
||||||
|
} else {
|
||||||
|
setCache(res, "no-store", 120);
|
||||||
|
}
|
||||||
|
res.json(data);
|
||||||
} else {
|
} else {
|
||||||
setCache(res, "public", 240)
|
setCache(res, "public", 240)
|
||||||
res.json(await ldb.get(id, false));
|
res.json(await ldb.get(id, false));
|
||||||
|
|
|
@ -18,6 +18,7 @@ async function getReasonCode(req, res, next) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("ERROR", err.message);
|
console.error("ERROR", err.message);
|
||||||
err.status = 500;
|
err.status = 500;
|
||||||
|
setCache(res, "no-store", 5)
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,21 +21,19 @@ module.exports = async function authCheck(
|
||||||
} else if (typeof id === "string") {
|
} else if (typeof id === "string") {
|
||||||
const authCheck = (await isAuthed(id)) || false;
|
const authCheck = (await isAuthed(id)) || false;
|
||||||
if (authCheck) {
|
if (authCheck) {
|
||||||
|
// Authenticate
|
||||||
req.isAuthed = true;
|
req.isAuthed = true;
|
||||||
logger.info("auth.middleware: Authentication Successful");
|
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
req.isAuthed = false;
|
req.isAuthed = false;
|
||||||
logger.info("auth.middleware: Authentication Failed");
|
logger.info("auth.middleware: Authentication Failed");
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
// Handle cases where UUID passed as an array
|
||||||
} else if (Array.isArray(id)) {
|
} else if (Array.isArray(id)) {
|
||||||
const authCheck = (await isAuthed(id[0])) || false;
|
const authCheck = (await isAuthed(id[0])) || false;
|
||||||
if (authCheck) {
|
if (authCheck) {
|
||||||
req.isAuthed = true;
|
req.isAuthed = true;
|
||||||
logger.warn(
|
|
||||||
"auth.middleware: UUID Passed as Array - Authentication Successful"
|
|
||||||
);
|
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
req.isAuthed = false;
|
req.isAuthed = false;
|
||||||
|
|
|
@ -141,6 +141,7 @@ async function staffApiCallRetry(api, method, options, retries) {
|
||||||
logger.warn(err, "DNS ERR")
|
logger.warn(err, "DNS ERR")
|
||||||
if (i < retries - 1) {
|
if (i < retries - 1) {
|
||||||
logger.debug('Retrying API Call')
|
logger.debug('Retrying API Call')
|
||||||
|
await delay(500)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,6 +151,10 @@ async function staffApiCallRetry(api, method, options, retries) {
|
||||||
throw new Error("Max retries exceeded");
|
throw new Error("Max retries exceeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delay(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
async function getReasonCodeList() {
|
async function getReasonCodeList() {
|
||||||
logger.debug("ldbService.getReasonCodeList: Fetching reason code list");
|
logger.debug("ldbService.getReasonCodeList: Fetching reason code list");
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue