trilium/routes/api/event_log.js

26 lines
705 B
JavaScript
Raw Normal View History

2017-11-04 11:00:35 +08:00
"use strict";
const express = require('express');
const router = express.Router();
const sql = require('../../services/sql');
2017-12-23 22:57:20 +08:00
const auth = require('../../services/auth');
2017-11-04 11:00:35 +08:00
2017-12-23 22:57:20 +08:00
router.get('', auth.checkApiAuth, async (req, res, next) => {
2017-11-04 11:00:35 +08:00
await deleteOld();
const result = await sql.getAll("SELECT * FROM event_log ORDER BY date_added DESC");
2017-11-04 11:00:35 +08:00
res.send(result);
});
async function deleteOld() {
const cutoffId = await sql.getFirstValue("SELECT id FROM event_log ORDER BY id DESC LIMIT 1000, 1");
2017-11-04 11:00:35 +08:00
if (cutoffId) {
await sql.doInTransaction(async () => {
await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]);
});
2017-11-04 11:00:35 +08:00
}
}
module.exports = router;