2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-16 07:47:05 +08:00
|
|
|
const sql = require('../../services/sql');
|
2018-11-07 00:47:40 +08:00
|
|
|
const protectedSessionService = require('../../services/protected_session');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
async function getRecentChanges() {
|
2018-01-30 06:41:59 +08:00
|
|
|
const recentChanges = await sql.getRows(
|
2019-09-03 02:26:18 +08:00
|
|
|
`
|
|
|
|
SELECT * FROM (
|
|
|
|
SELECT
|
|
|
|
notes.noteId,
|
|
|
|
notes.isDeleted AS current_isDeleted,
|
|
|
|
notes.title AS current_title,
|
|
|
|
notes.isProtected AS current_isProtected,
|
|
|
|
note_revisions.title,
|
|
|
|
note_revisions.utcDateModifiedTo AS date
|
|
|
|
FROM
|
|
|
|
note_revisions
|
|
|
|
JOIN notes USING(noteId)
|
|
|
|
ORDER BY
|
|
|
|
utcDateModifiedTo DESC
|
|
|
|
LIMIT 1000
|
|
|
|
)
|
|
|
|
UNION ALL SELECT * FROM (
|
|
|
|
SELECT
|
|
|
|
notes.noteId,
|
|
|
|
notes.isDeleted AS current_isDeleted,
|
|
|
|
notes.title AS current_title,
|
|
|
|
notes.isProtected AS current_isProtected,
|
|
|
|
notes.title,
|
|
|
|
notes.utcDateCreated AS date
|
|
|
|
FROM
|
|
|
|
notes
|
|
|
|
ORDER BY
|
|
|
|
utcDateCreated DESC
|
|
|
|
LIMIT 1000
|
|
|
|
)
|
|
|
|
ORDER BY date DESC
|
|
|
|
LIMIT 200`);
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2019-03-05 03:44:20 +08:00
|
|
|
for (const change of recentChanges) {
|
|
|
|
if (change.current_isProtected) {
|
|
|
|
if (protectedSessionService.isProtectedSessionAvailable()) {
|
2019-11-01 04:58:34 +08:00
|
|
|
change.title = protectedSessionService.decrypt(change.title);
|
|
|
|
change.current_title = protectedSessionService.decrypt(change.current_title);
|
2019-03-05 03:44:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-11-07 00:47:40 +08:00
|
|
|
change.title = change.current_title = "[Protected]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
return recentChanges;
|
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
module.exports = {
|
|
|
|
getRecentChanges
|
|
|
|
};
|