import express from 'express'; const router = express.Router(); // GET /api/log — 获取操作日志 router.get('/', async (_req, res) => { try { const Parse = (globalThis as any).Parse; const q = new Parse.Query('OperationLog'); q.descending('createdAt'); q.limit(500); const list = await q.find({ useMasterKey: true }); const data = list.map((l: any) => ({ id: l.id, action: l.get('action'), objectType: l.get('objectType'), objectId: l.get('objectId'), operatorId: l.get('operatorId'), operatorName: l.get('operatorName'), details: l.get('details'), ip: l.get('ip'), status: l.get('status'), timestamp: l.get('createdAt'), })); res.json(data); } catch (e: any) { res.status(500).json({ error: e.message }); } }); // POST /api/log — 添加操作日志 router.post('/', async (req, res) => { try { const Parse = (globalThis as any).Parse; const entry = req.body; const OperationLog = Parse.Object.extend('OperationLog'); const obj = new OperationLog(); obj.set('action', entry.action || ''); obj.set('objectType', entry.objectType || ''); obj.set('objectId', entry.objectId || ''); obj.set('operatorId', entry.operatorId || ''); obj.set('operatorName', entry.operatorName || ''); obj.set('details', entry.details || ''); obj.set('ip', entry.ip || ''); obj.set('status', entry.status || 'success'); const saved = await obj.save(null, { useMasterKey: true }); res.json({ ok: true, id: saved.id || '' }); } catch (e: any) { res.status(500).json({ error: e.message }); } }); export default router;