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