mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 01:56:33 +02:00 
			
		
		
		
	generate & send install-unique IDs
This commit is contained in:
		
							parent
							
								
									8653e43b2b
								
							
						
					
					
						commit
						96c1df5c3a
					
				
					 4 changed files with 21 additions and 2 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -6,3 +6,5 @@ node_modules
 | 
			
		|||
npm-debug.log
 | 
			
		||||
 | 
			
		||||
package-lock.json
 | 
			
		||||
 | 
			
		||||
/id.json
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								lib/generate-install-id.js
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								lib/generate-install-id.js
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#!/usr/bin/env node
 | 
			
		||||
 | 
			
		||||
const {randomBytes} = require('crypto')
 | 
			
		||||
 | 
			
		||||
const id = randomBytes(6).toString('hex')
 | 
			
		||||
process.stdout.write(JSON.stringify(id) + '\n')
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
'use strict'
 | 
			
		||||
 | 
			
		||||
const {join} = require('path')
 | 
			
		||||
const createHash = require('create-hash')
 | 
			
		||||
let captureStackTrace = () => {}
 | 
			
		||||
if (process.env.NODE_DEBUG === 'hafas-client') {
 | 
			
		||||
| 
						 | 
				
			
			@ -9,6 +10,15 @@ const {stringify} = require('query-string')
 | 
			
		|||
const Promise = require('pinkie-promise')
 | 
			
		||||
const {fetch} = require('fetch-ponyfill')({Promise})
 | 
			
		||||
 | 
			
		||||
let id
 | 
			
		||||
try {
 | 
			
		||||
	id = require('../id.json')
 | 
			
		||||
} catch (err) {
 | 
			
		||||
	const p = join(__dirname, '..', 'id.json')
 | 
			
		||||
	console.error(`Failed to load the install-unique ID from ${p}.`)
 | 
			
		||||
	process.exit(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const md5 = input => createHash('md5').update(input).digest()
 | 
			
		||||
 | 
			
		||||
const request = (profile, userAgent, opt, data) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +34,7 @@ const request = (profile, userAgent, opt, data) => {
 | 
			
		|||
			'Content-Type': 'application/json',
 | 
			
		||||
			'Accept-Encoding': 'gzip, deflate',
 | 
			
		||||
			'Accept': 'application/json',
 | 
			
		||||
			'user-agent': userAgent
 | 
			
		||||
			'user-agent': id + ' ' + userAgent
 | 
			
		||||
		},
 | 
			
		||||
		query: {}
 | 
			
		||||
	})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,6 +62,7 @@
 | 
			
		|||
	},
 | 
			
		||||
	"scripts": {
 | 
			
		||||
		"test": "env NODE_ENV=dev NODE_DEBUG=hafas-client node test/index.js",
 | 
			
		||||
		"prepublishOnly": "npm test | tap-spec"
 | 
			
		||||
		"prepublishOnly": "npm test | tap-spec",
 | 
			
		||||
		"install": "lib/generate-install-id.js >id.json"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue