From 76a476c8cdc832246478f6d45f613ea7f4061d34 Mon Sep 17 00:00:00 2001 From: tiagohm Date: Sun, 27 Oct 2024 09:55:10 -0300 Subject: [PATCH] [desktop]: Remove nuid dependency --- desktop/package-lock.json | 10 ---------- desktop/package.json | 1 - desktop/src/app/image/image.component.ts | 4 ++-- .../interceptors/idempotency-key.interceptor.ts | 4 ++-- desktop/src/shared/utils/random.ts | 11 +++++++++++ 5 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 desktop/src/shared/utils/random.ts diff --git a/desktop/package-lock.json b/desktop/package-lock.json index 2483ce57e..756d03174 100644 --- a/desktop/package-lock.json +++ b/desktop/package-lock.json @@ -25,7 +25,6 @@ "hotkeys-js": "3.13.7", "leaflet": "1.9.4", "ngx-moveable": "0.50.0", - "nuid": "2.0.1-2", "panzoom": "9.4.3", "primeflex": "3.3.1", "primeicons": "7.0.0", @@ -15301,15 +15300,6 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, - "node_modules/nuid": { - "version": "2.0.1-2", - "resolved": "https://registry.npmjs.org/nuid/-/nuid-2.0.1-2.tgz", - "integrity": "sha512-zL7Z5+CivaZyUdBn76Ih8rffXABBSe3hzazHBk7qXsF4/o5DPDsblXjs5KQRlgjkeLa6XSCd5/GJaShArI2WMQ==", - "license": "Apache-2.0", - "engines": { - "node": ">= 18.x" - } - }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", diff --git a/desktop/package.json b/desktop/package.json index d56fa75ec..f72521d5d 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -49,7 +49,6 @@ "hotkeys-js": "3.13.7", "leaflet": "1.9.4", "ngx-moveable": "0.50.0", - "nuid": "2.0.1-2", "panzoom": "9.4.3", "primeflex": "3.3.1", "primeicons": "7.0.0", diff --git a/desktop/src/app/image/image.component.ts b/desktop/src/app/image/image.component.ts index 75ad74efd..6da5ef184 100644 --- a/desktop/src/app/image/image.component.ts +++ b/desktop/src/app/image/image.component.ts @@ -2,7 +2,6 @@ import { AfterViewInit, Component, ElementRef, HostListener, NgZone, OnDestroy, import { ActivatedRoute } from '@angular/router' import hotkeys from 'hotkeys-js' import { NgxLegacyMoveableComponent, OnDrag, OnResize, OnRotate } from 'ngx-moveable' -import { nuid } from 'nuid' import createPanZoom from 'panzoom' import { ContextMenu } from 'primeng/contextmenu' import { DeviceListMenuComponent } from '../../shared/components/device-list-menu/device-list-menu.component' @@ -52,6 +51,7 @@ import { Mount } from '../../shared/types/mount.types' import { PlateSolverRequest } from '../../shared/types/platesolver.types' import { StarDetectionRequest } from '../../shared/types/stardetector.types' import { CoordinateInterpolator } from '../../shared/utils/coordinate-interpolation' +import { uid } from '../../shared/utils/random' import { AppComponent } from '../app.component' @Component({ @@ -530,7 +530,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy { this.loadPreference() - this.solver.key = nuid.next() + this.solver.key = uid() } async ngAfterViewInit() { diff --git a/desktop/src/shared/interceptors/idempotency-key.interceptor.ts b/desktop/src/shared/interceptors/idempotency-key.interceptor.ts index a89ffe54a..bd98db429 100644 --- a/desktop/src/shared/interceptors/idempotency-key.interceptor.ts +++ b/desktop/src/shared/interceptors/idempotency-key.interceptor.ts @@ -1,14 +1,14 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http' import { Injectable } from '@angular/core' -import { nuid } from 'nuid' import { Observable } from 'rxjs' +import { uid } from '../utils/random' @Injectable({ providedIn: 'root' }) export class IdempotencyKeyInterceptor implements HttpInterceptor { static readonly HEADER_KEY = 'X-Idempotency-Key' intercept(req: HttpRequest, next: HttpHandler): Observable> { - const idempotencyKey = nuid.next() + const idempotencyKey = uid() req = req.clone({ headers: req.headers.set(IdempotencyKeyInterceptor.HEADER_KEY, idempotencyKey), diff --git a/desktop/src/shared/utils/random.ts b/desktop/src/shared/utils/random.ts new file mode 100644 index 000000000..152814329 --- /dev/null +++ b/desktop/src/shared/utils/random.ts @@ -0,0 +1,11 @@ +const chars = 'abcdefghijklmnopqrstuvwxyz0123456789' + +export function uid(length: number = 12) { + const value = new Array(length) + + for (let i = 0; i < length; i++) { + value[i] = chars[Math.floor(Math.random() * 36)].codePointAt(0)! + } + + return String.fromCharCode.apply(null, value) +}