mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 16:28:46 +00:00
fix: replace crypto.randomUUID with polyfill for HTTP contexts
crypto.randomUUID() is only available in secure contexts (HTTPS/localhost). Add uuid() utility with fallback for HTTP deployments.
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
import type { AiConfig } from "@/stores/settingsStore";
|
||||
import { uuid } from "@/lib/utils";
|
||||
import type {
|
||||
ColumnInfo,
|
||||
ConnectionConfig,
|
||||
@@ -111,7 +112,7 @@ export async function runAiStream(
|
||||
|
||||
const messages: api.AiMessage[] = [...(history || []), { role: "user", content: userPrompt }];
|
||||
|
||||
const sid = sessionId || crypto.randomUUID();
|
||||
const sid = sessionId || uuid();
|
||||
const params = actionParams(input.action);
|
||||
|
||||
await api.aiStream(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ConnectionConfig, ConnectionGroup, SidebarLayout, SidebarOrderEntry, TreeNode } from "@/types/database";
|
||||
import { uuid } from "@/lib/utils";
|
||||
|
||||
export function emptyLayout(): SidebarLayout {
|
||||
return { groups: [], order: [] };
|
||||
@@ -234,7 +235,7 @@ function reorderConnection(
|
||||
}
|
||||
|
||||
export function createGroup(layout: SidebarLayout, name: string): { layout: SidebarLayout; groupId: string } {
|
||||
const groupId = crypto.randomUUID();
|
||||
const groupId = uuid();
|
||||
const group: ConnectionGroup = { id: groupId, name, collapsed: false };
|
||||
return {
|
||||
groupId,
|
||||
|
||||
@@ -5,3 +5,13 @@ import { twMerge } from "tailwind-merge";
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export function uuid(): string {
|
||||
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user