Added api route to check latest version
This commit is contained in:
parent
07881c57a1
commit
356a88e415
4 changed files with 30 additions and 3 deletions
|
@ -32,6 +32,8 @@
|
|||
"internal-ip": "^6.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mock-fs": "^5.1.2",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-fetch": "^3.2.4",
|
||||
"node-port-scanner": "^3.0.1",
|
||||
"p-iteration": "^1.1.8",
|
||||
"passport": "^0.5.2",
|
||||
|
@ -66,8 +68,8 @@
|
|||
"jest": "^28.1.0",
|
||||
"nodemon": "^2.0.15",
|
||||
"prettier": "2.6.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^28.0.2",
|
||||
"typescript": "4.6.4",
|
||||
"rimraf": "^3.0.2"
|
||||
"typescript": "4.6.4"
|
||||
}
|
||||
}
|
||||
|
|
5
packages/system-api/src/config/cache.ts
Normal file
5
packages/system-api/src/config/cache.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import cache from 'node-cache';
|
||||
|
||||
const TipiCache = new cache();
|
||||
|
||||
export default TipiCache;
|
|
@ -1,5 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import si from 'systeminformation';
|
||||
import fetch from 'node-fetch';
|
||||
import TipiCache from '../../config/cache';
|
||||
|
||||
type CpuData = {
|
||||
load: number;
|
||||
|
@ -69,4 +71,21 @@ const getMemoryInfo = async (req: Request, res: Response<MemoryData>) => {
|
|||
res.status(200).json(result);
|
||||
};
|
||||
|
||||
export default { getCpuInfo, getDiskInfo, getMemoryInfo };
|
||||
const getLatestVersion = async (req: Request, res: Response<string>) => {
|
||||
let version = TipiCache.get<string>('latestVersion');
|
||||
|
||||
console.log('CACHED', version);
|
||||
|
||||
if (!version) {
|
||||
const response = await fetch('https://api.github.com/repos/meienberger/runtipi/releases/latest');
|
||||
const json = (await response.json()) as { name: string };
|
||||
TipiCache.set('latestVersion', json.name);
|
||||
version = json.name;
|
||||
}
|
||||
|
||||
console.log(version);
|
||||
|
||||
res.status(200).send(version);
|
||||
};
|
||||
|
||||
export default { getCpuInfo, getDiskInfo, getMemoryInfo, getLatestVersion };
|
||||
|
|
|
@ -6,5 +6,6 @@ const router = Router();
|
|||
router.route('/cpu').get(SystemController.getCpuInfo);
|
||||
router.route('/disk').get(SystemController.getDiskInfo);
|
||||
router.route('/memory').get(SystemController.getMemoryInfo);
|
||||
router.route('/version/latest').get(SystemController.getLatestVersion);
|
||||
|
||||
export default router;
|
||||
|
|
Loading…
Reference in a new issue