mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 08:15:52 +01:00
server-ts: Convert routes/api/recent_notes
This commit is contained in:
24
src/routes/api/recent_notes.ts
Normal file
24
src/routes/api/recent_notes.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
import BRecentNote = require('../../becca/entities/brecent_note');
|
||||
import sql = require('../../services/sql');
|
||||
import dateUtils = require('../../services/date_utils');
|
||||
import { Request } from 'express';
|
||||
|
||||
function addRecentNote(req: Request) {
|
||||
new BRecentNote({
|
||||
noteId: req.body.noteId,
|
||||
notePath: req.body.notePath
|
||||
}).save();
|
||||
|
||||
if (Math.random() < 0.05) {
|
||||
// it's not necessary to run this every time ...
|
||||
const cutOffDate = dateUtils.utcDateTimeStr(new Date(Date.now() - 24 * 3600 * 1000));
|
||||
|
||||
sql.execute(`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]);
|
||||
}
|
||||
}
|
||||
|
||||
export = {
|
||||
addRecentNote
|
||||
};
|
||||
Reference in New Issue
Block a user