Refactor proxyFetch and enhance MediaProviderDetailPage layout

- Removed the isCloud check from proxyFetch.js, simplifying the fetch patching logic.
- Updated MediaProviderDetailPage to include a new section for API key retrieval, improving user experience with clearer layout and additional notice text.
- Enhanced ConnectionRow to better handle email display names.
- Improved ProviderDetailPage to conditionally render provider notices and API key links.
- Refactored localDb, requestDetailsDb, and usageDb to remove unnecessary isCloud checks, streamlining database interactions.
- Updated OAuthModal to combine waiting and manual input steps for a more cohesive user flow.
- Added API key URLs to several providers in providers.js for better accessibility.
This commit is contained in:
decolua
2026-05-01 17:03:13 +07:00
parent f8d2a9ff76
commit f410061e70
9 changed files with 144 additions and 147 deletions

View File

@@ -4,24 +4,21 @@ import path from "node:path";
import fs from "node:fs";
import { DATA_DIR } from "@/lib/dataDir.js";
const isCloud = typeof caches !== "undefined" && typeof caches === "object";
const DEFAULT_MAX_RECORDS = 200;
const DEFAULT_BATCH_SIZE = 20;
const DEFAULT_FLUSH_INTERVAL_MS = 5000;
const DEFAULT_MAX_JSON_SIZE = 5 * 1024; // 5KB default, configurable via settings
const CONFIG_CACHE_TTL_MS = 5000;
const MAX_TOTAL_DB_SIZE = 50 * 1024 * 1024; // 50MB hard limit for total DB file
const DB_FILE = isCloud ? null : path.join(DATA_DIR, "request-details.json");
const DB_FILE = path.join(DATA_DIR, "request-details.json");
if (!isCloud && !fs.existsSync(DATA_DIR)) {
if (!fs.existsSync(DATA_DIR)) {
fs.mkdirSync(DATA_DIR, { recursive: true });
}
let dbInstance = null;
async function getDb() {
if (isCloud) return null;
if (!dbInstance) {
const adapter = new JSONFile(DB_FILE);
const db = new Low(adapter, { records: [] });
@@ -107,7 +104,7 @@ function generateDetailId(model) {
}
async function flushToDatabase() {
if (isCloud || isFlushing || writeBuffer.length === 0) return;
if (isFlushing || writeBuffer.length === 0) return;
isFlushing = true;
try {
@@ -178,8 +175,6 @@ async function flushToDatabase() {
}
export async function saveRequestDetail(detail) {
if (isCloud) return;
const config = await getObservabilityConfig();
if (!config.enabled) return;
@@ -197,10 +192,6 @@ export async function saveRequestDetail(detail) {
}
export async function getRequestDetails(filter = {}) {
if (isCloud) {
return { details: [], pagination: { page: 1, pageSize: 50, totalItems: 0, totalPages: 0, hasNext: false, hasPrev: false } };
}
const db = await getDb();
let records = [...db.data.records];
@@ -228,8 +219,6 @@ export async function getRequestDetails(filter = {}) {
}
export async function getRequestDetailById(id) {
if (isCloud) return null;
const db = await getDb();
return db.data.records.find(r => r.id === id) || null;
}
@@ -241,8 +230,6 @@ const _shutdownHandler = async () => {
};
function ensureShutdownHandler() {
if (isCloud) return;
// Remove any previously registered listeners from this module (hot-reload safety)
process.off("beforeExit", _shutdownHandler);
process.off("SIGINT", _shutdownHandler);