Spaces:
Runtime error
Runtime error
Download controllers/errorLogController.js from faridaqurr/tinfo-web-server: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/faridaqurr/tinfo-web-server/resolve/main/controllers/errorLogController.js
- Command line
-
hf download hf://spaces/faridaqurr/tinfo-web-server/controllers/errorLogController.js
-
curl -L -o errorLogController.js https://huggingface.co/spaces/faridaqurr/tinfo-web-server/resolve/main/controllers/errorLogController.js
1.42 kB
| const { asyncController } = require('../utils/asyncController'); | |
| const { getMemoryLog, clearMemoryLog } = require('../utils/errorLogger'); | |
| const { env } = require('../configs/env'); | |
| const parsePage = (val, fallback) => { | |
| const n = parseInt(String(val || ''), 10); | |
| return Number.isInteger(n) && n > 0 ? n : fallback; | |
| }; | |
| const getErrorLogs = asyncController(async (req, res) => { | |
| const page = parsePage(req.query.page, 1); | |
| const pageSize = Math.min(100, parsePage(req.query.pageSize, 50)); | |
| let items; | |
| let total; | |
| if (env.isProduction) { | |
| const ErrorLog = require('../models/ErrorLog'); | |
| const skip = (page - 1) * pageSize; | |
| [total, items] = await Promise.all([ | |
| ErrorLog.countDocuments(), | |
| ErrorLog.find().sort({ timestamp: -1 }).skip(skip).limit(pageSize).lean(), | |
| ]); | |
| } else { | |
| const all = getMemoryLog(); | |
| total = all.length; | |
| const skip = (page - 1) * pageSize; | |
| items = all.slice(skip, skip + pageSize); | |
| } | |
| res.json({ | |
| success: true, | |
| items, | |
| total, | |
| page, | |
| pageSize, | |
| totalPages: Math.max(1, Math.ceil((total || 0) / pageSize)), | |
| }); | |
| }); | |
| const clearErrorLogs = asyncController(async (req, res) => { | |
| clearMemoryLog(); | |
| if (env.isProduction) { | |
| const ErrorLog = require('../models/ErrorLog'); | |
| await ErrorLog.deleteMany({}); | |
| } | |
| res.json({ success: true, cleared: true }); | |
| }); | |
| module.exports = { getErrorLogs, clearErrorLogs }; | |