|
@@ -4,8 +4,9 @@ const {getRustConfig} = require('./config')
|
|
|
const http = require("./utils/http");
|
|
|
// const file = require('./utils/file')
|
|
|
const {logger} = require("./utils/logger");
|
|
|
+const path = require("path");
|
|
|
+const fs = require('fs');
|
|
|
// const {spawn, exec, fork, execSync} = require("child_process");
|
|
|
-// const path = require("path");
|
|
|
|
|
|
// const {ka, tr} = require("date-fns/locale");
|
|
|
// const {getAppMap} = require("./robot");
|
|
@@ -143,6 +144,38 @@ function init() {
|
|
|
robot.searchPositions(param)
|
|
|
res.send({'code': 200, 'data': true, "message": "SUCCESS"});
|
|
|
})
|
|
|
+
|
|
|
+ // 下载数据文件
|
|
|
+ app.get('/downloadDataFile', (req, res) => {
|
|
|
+ const param = req.query;
|
|
|
+ const id = param.id
|
|
|
+ let port = -1;
|
|
|
+ robot.appMap.forEach((value, key) => {
|
|
|
+ if (value.id + "" === id + "") {
|
|
|
+ port = value.port
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const logPath = "./db" + port;
|
|
|
+ const directoryPath = path.resolve(logPath);
|
|
|
+ // logger.info('文件目录:' + directoryPath)
|
|
|
+ const latestFile = getLatestFile(directoryPath);
|
|
|
+
|
|
|
+ if (!latestFile) {
|
|
|
+ return res.status(404).send('没有找到文件。');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置下载响应
|
|
|
+ res.download(latestFile, err => {
|
|
|
+ if (err) {
|
|
|
+ console.error('下载文件时发生错误:', err);
|
|
|
+ res.status(500).send('下载失败');
|
|
|
+ } else {
|
|
|
+ console.log('文件下载成功:', latestFile);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
// 新策略-返回机器人状态
|
|
|
app.get('/predictorState', (req, res) => {
|
|
|
const param = req.query;
|
|
@@ -197,6 +230,24 @@ function isOK(req, res) {
|
|
|
res.send({'code': 200, 'data': "null", "message": "SUCCESS"});
|
|
|
}
|
|
|
|
|
|
+function getLatestFile(dir) {
|
|
|
+ const files = fs.readdirSync(dir);
|
|
|
+ let latestFile = null;
|
|
|
+ let latestStat = null;
|
|
|
+
|
|
|
+ files.forEach(file => {
|
|
|
+ const filePath = path.join(dir, file);
|
|
|
+ const stat = fs.statSync(filePath);
|
|
|
+
|
|
|
+ if (!latestStat || stat.birthtime > latestStat.birthtime) {
|
|
|
+ latestStat = stat;
|
|
|
+ latestFile = filePath;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return latestFile;
|
|
|
+}
|
|
|
+
|
|
|
// 日志读取操作
|
|
|
module.exports = {
|
|
|
init,
|