provide more general function for generating random strings
This commit is contained in:
		
							parent
							
								
									7bba4a56b0
								
							
						
					
					
						commit
						3c13e8093b
					
				
					 1 changed files with 3 additions and 3 deletions
				
			
		|  | @ -82,8 +82,8 @@ function handle(msg) { | ||||||
| 
 | 
 | ||||||
| // basic functions - move to api.ts
 | // basic functions - move to api.ts
 | ||||||
| 
 | 
 | ||||||
| function createSid(): string { | function createRandString(size: number): string { | ||||||
| 	const arr = new Uint32Array(2) | 	const arr = new Uint32Array(size) | ||||||
| 	crypto.getRandomValues(arr) | 	crypto.getRandomValues(arr) | ||||||
| 	const result: string[] = [] | 	const result: string[] = [] | ||||||
| 	arr.forEach((x) => result.push(x.toString(36))) | 	arr.forEach((x) => result.push(x.toString(36))) | ||||||
|  | @ -94,7 +94,7 @@ function getSid(): string { | ||||||
| 	const sid_key = 'api.sessionid' | 	const sid_key = 'api.sessionid' | ||||||
| 	let sid = localStorage.getItem(sid_key) | 	let sid = localStorage.getItem(sid_key) | ||||||
| 	if (!sid) { | 	if (!sid) { | ||||||
| 		sid = createSid() | 		sid = createRandString(2) | ||||||
| 		localStorage.setItem(sid_key, sid) | 		localStorage.setItem(sid_key, sid) | ||||||
| 	} | 	} | ||||||
| 	return sid | 	return sid | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue