Move generate userID to shared lib

This commit is contained in:
Ajay
2023-02-18 02:54:42 -05:00
parent 1d05c2b3df
commit 4ca6a331f1
4 changed files with 11 additions and 30 deletions

14
package-lock.json generated
View File

@@ -27,7 +27,7 @@
],
"license": "LGPL-3.0-or-later",
"dependencies": {
"@ajayyy/maze-utils": "^1.1.3",
"@ajayyy/maze-utils": "^1.1.4",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
@@ -68,9 +68,9 @@
}
},
"node_modules/@ajayyy/maze-utils": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
"integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ==",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz",
"integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ==",
"funding": [
{
"type": "individual",
@@ -13420,9 +13420,9 @@
},
"dependencies": {
"@ajayyy/maze-utils": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
"integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ=="
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz",
"integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ=="
},
"@ampproject/remapping": {
"version": "2.2.0",

View File

@@ -4,7 +4,7 @@
"description": "",
"main": "background.js",
"dependencies": {
"@ajayyy/maze-utils": "^1.1.3",
"@ajayyy/maze-utils": "^1.1.4",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"

View File

@@ -5,13 +5,13 @@ import { Registration } from "./types";
import registerContentScript from 'content-scripts-register-polyfill/ponyfill.js';
import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "@ajayyy/maze-utils/lib/background-request-proxy";
import { setupTabUpdates } from "@ajayyy/maze-utils/lib/tab-updates";
import { generateUserID } from "@ajayyy/maze-utils/lib/setup";
// Make the config public for debugging purposes
window.SB = Config;
import Utils from "./utils";
import { GenericUtils } from "./utils/genericUtils";
const utils = new Utils({
registerFirefoxContentScript,
unregisterFirefoxContentScript
@@ -106,7 +106,7 @@ chrome.runtime.onInstalled.addListener(function () {
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
//generate a userID
const newUserID = GenericUtils.generateUserID();
const newUserID = generateUserID();
//save this UUID
Config.config.userID = newUserID;
@@ -157,7 +157,7 @@ async function submitVote(type: number, UUID: string, category: string) {
if (userID == undefined || userID === "undefined") {
//generate one
userID = GenericUtils.generateUserID();
userID = generateUserID();
Config.config.userID = userID;
}

View File

@@ -49,27 +49,8 @@ function indexesOf<T>(array: T[], value: T): number[] {
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
}
function generateUserID(length = 36): string {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
if (window.crypto && window.crypto.getRandomValues) {
const values = new Uint32Array(length);
window.crypto.getRandomValues(values);
for (let i = 0; i < length; i++) {
result += charset[values[i] % charset.length];
}
return result;
} else {
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
}
export const GenericUtils = {
getErrorMessage,
getLuminance,
generateUserID,
indexesOf
}