Незакоммиченная работа: UI заявок/планирования и правки сервисов

- pcp-tgu-ops-ui: вкладка «Заявки», редактор планирования, утилиты uuid
  и e2e-verify скрипты, обновление зависимостей
- pcp-ballistics-service, pcp-mission-planing-service: текущие правки
This commit is contained in:
Дмитрий Соловьев
2026-06-02 11:04:45 +03:00
parent 96f698112b
commit bd59204fcf
13 changed files with 588 additions and 40 deletions
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { generateUuid, uuidV4Fallback } from "./uuid";
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
describe("generateUuid", () => {
it("возвращает валидный UUID v4", () => {
expect(generateUuid()).toMatch(UUID_V4);
});
});
describe("uuidV4Fallback (insecure context)", () => {
it("даёт валидный UUID v4 без crypto.randomUUID", () => {
expect(uuidV4Fallback()).toMatch(UUID_V4);
});
it("генерирует разные значения", () => {
expect(uuidV4Fallback()).not.toBe(uuidV4Fallback());
});
});
+35
View File
@@ -0,0 +1,35 @@
/**
* Генерация UUID v4.
*
* `crypto.randomUUID()` доступен только в secure context (https или localhost),
* поэтому при открытии фронта по сетевому адресу (http://<ip>:5174) он отсутствует
* и падает с «crypto.randomUUID is not a function». `crypto.getRandomValues`, наоборот,
* доступен и в insecure context — используем его как фолбэк (RFC 4122 v4).
*/
export function generateUuid(): string {
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
return uuidV4Fallback();
}
/** RFC 4122 v4 на основе crypto.getRandomValues (работает в insecure context). */
export function uuidV4Fallback(): string {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40; // версия 4
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 10xx
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
return (
hex.slice(0, 4).join("") +
"-" +
hex.slice(4, 6).join("") +
"-" +
hex.slice(6, 8).join("") +
"-" +
hex.slice(8, 10).join("") +
"-" +
hex.slice(10, 16).join("")
);
}