mirror of
https://github.com/zadam/trilium.git
synced 2024-11-14 03:40:27 +08:00
44 lines
No EOL
974 B
JavaScript
44 lines
No EOL
974 B
JavaScript
const utils = require('./utils');
|
|
const log = require('./log');
|
|
const sql = require('./sql');
|
|
|
|
async function generateSourceId() {
|
|
const sourceId = utils.randomString(12);
|
|
|
|
log.info("Generated sourceId=" + sourceId);
|
|
|
|
await sql.doInTransaction(async () => {
|
|
await sql.insert("source_ids", {
|
|
source_id: sourceId,
|
|
date_created: utils.nowDate()
|
|
});
|
|
});
|
|
|
|
await refreshSourceIds();
|
|
|
|
return sourceId;
|
|
}
|
|
|
|
async function refreshSourceIds() {
|
|
allSourceIds = await sql.getFlattenedResults("SELECT source_id FROM source_ids ORDER BY date_created DESC");
|
|
}
|
|
|
|
let allSourceIds = [];
|
|
|
|
sql.dbReady.then(refreshSourceIds);
|
|
|
|
function isLocalSourceId(srcId) {
|
|
return allSourceIds.includes(srcId);
|
|
}
|
|
|
|
const currentSourceIdPromise = generateSourceId();
|
|
|
|
async function getCurrentSourceId() {
|
|
return await currentSourceIdPromise;
|
|
}
|
|
|
|
module.exports = {
|
|
generateSourceId,
|
|
getCurrentSourceId,
|
|
isLocalSourceId
|
|
}; |