trilium/services/source_id.js
2017-12-14 22:16:26 -05:00

32 lines
No EOL
754 B
JavaScript

const utils = require('./utils');
const log = require('./log');
const sql = require('./sql');
const currentSourceId = utils.randomString(12);
log.info("Using sourceId=" + currentSourceId);
let allSourceIds = [];
sql.dbReady.then(async () => {
try {
await sql.doInTransaction(async () => {
await sql.insert("source_ids", {
source_id: currentSourceId,
date_created: utils.nowDate()
});
});
allSourceIds = await sql.getFlattenedResults("SELECT source_id FROM source_ids ORDER BY date_created DESC");
}
catch (e) {}
});
function isLocalSourceId(srcId) {
return allSourceIds.includes(srcId);
}
module.exports = {
currentSourceId,
isLocalSourceId
};