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