Browse Source

下载数据文件更改为 指定下载端口号文件

JiahengHe 2 months ago
parent
commit
6605a6dd00
1 changed files with 2 additions and 22 deletions
  1. 2 22
      src/web.js

+ 2 - 22
src/web.js

@@ -158,10 +158,8 @@ function init() {
         if (port === -1){
             return res.status(404).send('机器人不存在!');
         }
-        const logPath = "./db" + port;
-        const directoryPath = path.resolve(logPath);
-        // logger.info('文件目录:' + directoryPath)
-        const latestFile = getLatestFile(directoryPath);
+        const logPath = "./db/" + port + ".html";
+        const latestFile = path.resolve(logPath);
 
         if (!latestFile) {
             return res.status(404).send('没有找到文件。');
@@ -233,24 +231,6 @@ 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,