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:
t8y2
2026-05-05 23:51:07 +08:00
parent 4e5a7cb40a
commit 0aa562f6ee
16 changed files with 48 additions and 23 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import { uuid } from "@/lib/utils";
import { ref, watch } from "vue";
import type { ColumnInfo, ConnectionConfig, SidebarLayout, TreeNode } from "@/types/database";
import { orderPinnedFirst } from "@/lib/pinnedItems";
@@ -866,7 +867,7 @@ export const useConnectionStore = defineStore("connection", () => {
(c) => c.name === config.name && c.host === config.host && c.port === config.port,
);
if (!duplicate) {
config.id = crypto.randomUUID();
config.id = uuid();
const normalized = normalizeConnection(config);
await addConnection(normalized);
count++;
+2 -1
View File
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import { uuid } from "@/lib/utils";
import { ref } from "vue";
import * as api from "@/lib/api";
import type { HistoryEntry } from "@/lib/api";
@@ -19,7 +20,7 @@ export const useHistoryStore = defineStore("history", () => {
async function add(entry: Omit<HistoryEntry, "id" | "executed_at">) {
const full: HistoryEntry = {
...entry,
id: crypto.randomUUID(),
id: uuid(),
executed_at: new Date().toISOString(),
};
await api.saveHistory(full);
+4 -3
View File
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import { uuid } from "@/lib/utils";
import { ref, watch } from "vue";
import type { DatabaseType, QueryTab } from "@/types/database";
import { orderPinnedFirst } from "@/lib/pinnedItems";
@@ -87,7 +88,7 @@ export const useQueryStore = defineStore("query", () => {
}
}
const id = crypto.randomUUID();
const id = uuid();
const tab: QueryTab = {
id,
title: title || `Query ${tabs.value.length + 1}`,
@@ -222,7 +223,7 @@ export const useQueryStore = defineStore("query", () => {
const tab = tabs.value.find((t) => t.id === id);
if (!tab || !sql.trim()) return;
const executionId = crypto.randomUUID();
const executionId = uuid();
tab.isExecuting = true;
tab.isCancelling = false;
tab.executionId = executionId;
@@ -270,7 +271,7 @@ export const useQueryStore = defineStore("query", () => {
return built;
}
const executionId = crypto.randomUUID();
const executionId = uuid();
tab.isExplaining = true;
tab.explainExecutionId = executionId;
tab.explainError = undefined;