const express = require('express');
const cluster = require('cluster');
const os = require('os');function formatDate() {let date = new Date();const day = date.getDate().toString().padStart(2, '0');const month = (date.getMonth() + 1).toString().padStart(2, '0'); const year = date.getFullYear();const hours = date.getHours().toString().padStart(2, '0');const minutes = date.getMinutes().toString().padStart(2, '0');const seconds = date.getSeconds().toString().padStart(2, '0');return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
const numCPUs = os.cpus().length;
a = undefined
if (cluster.isMaster) {console.log(`master ${process.pid} running`);for (let i = 0; i < numCPUs; i++) {cluster.fork();}cluster.on('exit', (worker, code, signal) => {console.log(`工作进程 ${worker.process.pid} 已退出`);});
} else {const app = express();app.get('/encryptPassword', (req, res) => {let keyId = req.query.keyId;let publicKey = req.query.publicKey;let version = req.query.version;let password = req.query.password;version = isNaN(parseInt(version)) ? 0 : parseInt(version);if (keyId && publicKey && version && password) {func(keyId, publicKey, version, password).then(result=>{console.log(formatDate() +" "+result)res.send({status: "ok", password: result})}).catch(err=>{console.log(formatDate() +" "+err)res.send({status: "no", error: err.toString()})})} else {res.send('Error')}});app.listen(8848, () => {console.log(`worker ${process.pid} running`);});
}