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
+3 -19
View File
@@ -5,12 +5,11 @@ import path from "path";
import fs from "fs";
import { DATA_DIR } from "@/lib/dataDir.js";
const isCloud = typeof caches !== 'undefined' || typeof caches === 'object';
const DB_FILE = isCloud ? null : path.join(DATA_DIR, "usage.json");
const LOG_FILE = isCloud ? null : path.join(DATA_DIR, "log.txt");
const DB_FILE = path.join(DATA_DIR, "usage.json");
const LOG_FILE = path.join(DATA_DIR, "log.txt");
// Ensure data directory exists
if (!isCloud && fs && typeof fs.existsSync === "function") {
if (fs && typeof fs.existsSync === "function") {
try {
if (!fs.existsSync(DATA_DIR)) {
fs.mkdirSync(DATA_DIR, { recursive: true });
@@ -231,15 +230,6 @@ export async function getActiveRequests() {
* Get usage database instance (singleton)
*/
export async function getUsageDb() {
if (isCloud) {
// Return in-memory DB for Workers
if (!dbInstance) {
dbInstance = new Low({ read: async () => {}, write: async () => {} }, defaultData);
dbInstance.data = defaultData;
}
return dbInstance;
}
if (!dbInstance) {
const adapter = new JSONFile(DB_FILE);
dbInstance = new Low(adapter, defaultData);
@@ -279,8 +269,6 @@ export async function getUsageDb() {
* @param {object} entry - Usage entry { provider, model, tokens: { prompt_tokens, completion_tokens, ... }, connectionId?, apiKey? }
*/
export async function saveRequestUsage(entry) {
if (isCloud) return; // Skip saving in Workers
try {
const db = await getUsageDb();
@@ -366,8 +354,6 @@ function formatLogDate(date = new Date()) {
* Format: datetime(dd-mm-yyyy h:m:s) | model | provider | account | tokens sent | tokens received | status
*/
export async function appendRequestLog({ model, provider, connectionId, tokens, status }) {
if (isCloud) return; // Skip logging in Workers
try {
const timestamp = formatLogDate();
const p = provider?.toUpperCase() || "-";
@@ -406,8 +392,6 @@ export async function appendRequestLog({ model, provider, connectionId, tokens,
* Get last N lines of log.txt
*/
export async function getRecentLogs(limit = 200) {
if (isCloud) return []; // Skip in Workers
// Runtime check: ensure fs module is available
if (!fs || typeof fs.existsSync !== "function") {
console.error("[usageDb] fs module not available in this environment");