2017-11-22 11:11:27 +08:00
|
|
|
const sql = require('./sql');
|
|
|
|
const utils = require('./utils');
|
|
|
|
const options = require('./options');
|
|
|
|
|
2017-12-16 10:14:10 +08:00
|
|
|
function getHash(rows) {
|
|
|
|
let hash = '';
|
|
|
|
|
2017-11-22 11:11:27 +08:00
|
|
|
for (const row of rows) {
|
|
|
|
hash = utils.hash(hash + JSON.stringify(row));
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2017-12-16 10:14:10 +08:00
|
|
|
async function getHashes() {
|
|
|
|
const optionsQuestionMarks = Array(options.SYNCED_OPTIONS.length).fill('?').join(',');
|
2017-11-22 11:11:27 +08:00
|
|
|
|
2017-12-16 10:14:10 +08:00
|
|
|
return {
|
2017-12-24 00:02:38 +08:00
|
|
|
notes: getHash(await sql.getAll(`SELECT
|
2017-12-16 10:14:10 +08:00
|
|
|
note_id,
|
|
|
|
note_title,
|
|
|
|
note_text,
|
|
|
|
date_modified,
|
|
|
|
is_protected,
|
|
|
|
is_deleted
|
|
|
|
FROM notes
|
|
|
|
ORDER BY note_id`)),
|
2017-11-22 11:11:27 +08:00
|
|
|
|
2017-12-24 00:02:38 +08:00
|
|
|
notes_tree: getHash(await sql.getAll(`SELECT
|
2017-12-16 10:14:10 +08:00
|
|
|
note_tree_id,
|
|
|
|
note_id,
|
2017-12-20 10:40:48 +08:00
|
|
|
parent_note_id,
|
|
|
|
note_position,
|
2017-12-16 10:14:10 +08:00
|
|
|
date_modified,
|
|
|
|
is_deleted,
|
|
|
|
prefix
|
|
|
|
FROM notes_tree
|
|
|
|
ORDER BY note_tree_id`)),
|
2017-11-22 11:11:27 +08:00
|
|
|
|
2017-12-24 00:02:38 +08:00
|
|
|
notes_history: getHash(await sql.getAll(`SELECT
|
2017-12-16 10:14:10 +08:00
|
|
|
note_history_id,
|
|
|
|
note_id,
|
|
|
|
note_title,
|
|
|
|
note_text,
|
|
|
|
date_modified_from,
|
|
|
|
date_modified_to
|
|
|
|
FROM notes_history
|
|
|
|
ORDER BY note_history_id`)),
|
2017-11-22 11:11:27 +08:00
|
|
|
|
2017-12-24 00:02:38 +08:00
|
|
|
recent_notes: getHash(await sql.getAll(`SELECT
|
2017-12-16 10:14:10 +08:00
|
|
|
note_tree_id,
|
|
|
|
note_path,
|
|
|
|
date_accessed,
|
|
|
|
is_deleted
|
|
|
|
FROM recent_notes
|
|
|
|
ORDER BY note_path`)),
|
2017-11-22 11:11:27 +08:00
|
|
|
|
2017-12-24 00:02:38 +08:00
|
|
|
options: getHash(await sql.getAll(`SELECT
|
2017-12-16 10:14:10 +08:00
|
|
|
opt_name,
|
|
|
|
opt_value
|
|
|
|
FROM options
|
|
|
|
WHERE opt_name IN (${optionsQuestionMarks})
|
|
|
|
ORDER BY opt_name`, options.SYNCED_OPTIONS))
|
|
|
|
};
|
2017-11-22 11:11:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-12-16 10:14:10 +08:00
|
|
|
getHashes
|
2017-11-22 11:11:27 +08:00
|
|
|
};
|