From d2263a3ec3e72363fe3202872ea8e3bfa9dbc4e3 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Mon, 30 Mar 2026 08:31:41 +0700 Subject: [PATCH] Update socket_io_provider.ts --- BACKEND/providers/socket_io_provider.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 35aa6d3..11ebbd5 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -310,10 +310,22 @@ export class WebSocketIo { }) socket.on('get_list_logs', async (data) => { + const dir = 'storage/system_logs' let getListSystemLogs = fs - .readdirSync('storage/system_logs') - .map((f) => 'storage/system_logs/' + f) + .readdirSync(dir) + .map((file) => { + const fullPath = `${dir}/${file}` + const stat = fs.statSync(fullPath) + + return { + path: fullPath, + time: stat.mtime.getTime(), // hoặc stat.birthtime + } + }) + .sort((a, b) => b.time - a.time) // giảm dần (mới nhất trước) .slice(0, 1000) + .map((f) => f.path) // lấy lại path + io.to(socket.id).emit('list_logs', getListSystemLogs) // const listHistory = await this.getHistory(data?.stationId, data?.lineId)