From 605e2be72dd982dacdacd803bf357dcd4beda1c2 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Thu, 11 Jan 2024 17:30:51 +0000 Subject: [PATCH] refactor: use `crypto.randomUUID` vs `uuid.v4` (#249) * refactor: use randomUUID vs uuidv4 * chore: don't import the node version * chore: no need to non-null assert here --- package.json | 2 -- pnpm-lock.yaml | 15 --------------- src/utils/storage/servers.ts | 1 - src/utils/store/api.ts | 12 ++++-------- 4 files changed, 4 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 2f34fa7..4369a01 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log#v1", "tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store", "typescript": "^5.3.3", - "uuid": "^9.0.1", "vite-plugin-svgr": "^4.2.0", "wavesurfer.js": "^7.6.1", "zustand": "^4.4.7" @@ -53,7 +52,6 @@ "devDependencies": { "@biomejs/biome": "^1.5.0", "@tauri-apps/cli": "^1.5.9", - "@types/uuid": "^9.0.7", "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.56.0", "eslint-plugin-react": "^7.33.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb15889..0e42875 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,9 +104,6 @@ dependencies: typescript: specifier: ^5.3.3 version: 5.3.3 - uuid: - specifier: ^9.0.1 - version: 9.0.1 vite-plugin-svgr: specifier: ^4.2.0 version: 4.2.0(typescript@5.3.3)(vite@5.0.11) @@ -124,9 +121,6 @@ devDependencies: '@tauri-apps/cli': specifier: ^1.5.9 version: 1.5.9 - '@types/uuid': - specifier: ^9.0.7 - version: 9.0.7 '@vitejs/plugin-react': specifier: ^4.2.1 version: 4.2.1(vite@5.0.11) @@ -1609,10 +1603,6 @@ packages: resolution: {integrity: sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==} dev: false - /@types/uuid@9.0.7: - resolution: {integrity: sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==} - dev: true - /@ungap/structured-clone@1.2.0: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} @@ -4192,11 +4182,6 @@ packages: react: 18.2.0 dev: false - /uuid@9.0.1: - resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} - hasBin: true - dev: false - /vfile-message@4.0.2: resolution: {integrity: sha512-jRDZ1IMLttGj41KcZvlrYAaI3CfqpLpfpf+Mfig13viT6NKvRzWZ+lXz0Y5D60w6uJIBAOGq9mSHf0gktF0duw==} dependencies: diff --git a/src/utils/storage/servers.ts b/src/utils/storage/servers.ts index 6177887..f19bc39 100644 --- a/src/utils/storage/servers.ts +++ b/src/utils/storage/servers.ts @@ -1,6 +1,5 @@ import { RecommendedServerInfo } from "@jellyfin/sdk"; import { Store } from "tauri-plugin-store-api"; -import { v4 as uuidv4 } from "uuid"; interface ServerInfo extends RecommendedServerInfo { id: string; diff --git a/src/utils/store/api.ts b/src/utils/store/api.ts index e840dd3..9851245 100644 --- a/src/utils/store/api.ts +++ b/src/utils/store/api.ts @@ -5,7 +5,6 @@ import { version as appVer } from "../../../package.json"; // Initial custom axios client to use tauri's http module import axios from "axios"; import axiosTauriApiAdapter from "axios-tauri-api-adapter"; -import { v4 as uuidv4 } from "uuid"; export const axiosClient = axios.create({ adapter: axiosTauriApiAdapter, @@ -15,13 +14,10 @@ export const axiosClient = axios.create({ timeout: 60000, }); -let deviceId = localStorage.getItem("deviceId"); +const deviceId = localStorage.getItem("deviceId") || crypto.randomUUID(); -if (!deviceId) { - const randomId = uuidv4(); - localStorage.setItem("deviceId", randomId); - - deviceId = randomId; +if (!localStorage.getItem("deviceId")) { + localStorage.setItem("deviceId", deviceId); } const jellyfin = new Jellyfin({ @@ -31,7 +27,7 @@ const jellyfin = new Jellyfin({ }, deviceInfo: { name: "JellyPlayer", - id: deviceId!, + id: deviceId, }, });