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();
|
|
|
|
|
2017-12-24 00:02:38 +08:00
|
|
|
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() {
|
2017-12-24 00:02:38 +08:00
|
|
|
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) {
|
2017-11-29 06:24:08 +08:00
|
|
|
await sql.doInTransaction(async () => {
|
|
|
|
await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]);
|
2017-11-29 06:04:47 +08:00
|
|
|
});
|
2017-11-04 11:00:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router;
|