trilium/services/source_id.js

30 lines
663 B
JavaScript
Raw Normal View History

const utils = require('./utils');
2017-11-07 08:23:35 +08:00
const log = require('./log');
const sql = require('./sql');
const currentSourceId = utils.randomString(12);
2017-11-07 08:23:35 +08:00
log.info("Using sourceId=" + currentSourceId);
2017-11-07 08:23:35 +08:00
let allSourceIds = [];
sql.dbReady.then(async () => {
2017-11-17 11:18:25 +08:00
try {
sql.insert("source_ids", {
source_id: currentSourceId,
date_created: utils.nowTimestamp()
});
2017-11-17 11:18:25 +08:00
allSourceIds = await sql.getFlattenedResults("source_id", "SELECT source_id FROM source_ids");
}
catch (e) {}
});
function isLocalSourceId(srcId) {
return allSourceIds.includes(srcId);
}
module.exports = {
currentSourceId,
isLocalSourceId
};