Add new dependencies and update file paths
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
67
routes/BuildMetaData.js
Normal file
67
routes/BuildMetaData.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const os = require('os');
|
||||
const child_process = require('child_process');
|
||||
const packageJson = require('../package.json');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function getAllFiles(dirPath, arrayOfFiles) {
|
||||
const files = fs.readdirSync(dirPath);
|
||||
|
||||
arrayOfFiles = arrayOfFiles || [];
|
||||
|
||||
files.forEach(function(file) {
|
||||
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
|
||||
} else {
|
||||
arrayOfFiles.push(path.join(dirPath, "/", file));
|
||||
}
|
||||
});
|
||||
|
||||
return arrayOfFiles;
|
||||
}
|
||||
|
||||
function bytesToSize(bytes) {
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
if (bytes == 0) return '0 Byte';
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
||||
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
function calculateBuildSize(files) {
|
||||
let totalSize = 0;
|
||||
|
||||
files.forEach(file => {
|
||||
const stats = fs.statSync(file);
|
||||
totalSize += stats.size;
|
||||
});
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
|
||||
const clientIp = req.headers['cf-connecting-ip'] || req.ip;
|
||||
const version = packageJson.version;
|
||||
const expressVersion = require('express/package.json').version;
|
||||
|
||||
const buildMetadata = {
|
||||
build_version: version,
|
||||
node_version: process.version,
|
||||
express_version: expressVersion,
|
||||
build_sha: child_process.execSync('git rev-parse HEAD').toString().trim(),
|
||||
os_type: os.type(),
|
||||
os_release: os.release(),
|
||||
};
|
||||
|
||||
|
||||
res.json(buildMetadata);
|
||||
} catch (error) {
|
||||
console.error('Error in /build-metadata: ', error);
|
||||
res.status(500).send('Error in /build-metadata: ' + error.toString());
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user