refactor: 替换服务端 console.log/error 为 winston logger
- folder-action.ts: 18处 console.log -> log.error - auth-action.ts: 4处 console.error -> log.error - dictionary-action/service.ts: 3处 -> log.error - translator-action/service.ts: 3处 -> log.error - bigmodel/translator/orchestrator.ts: console -> log.debug/info/error - bigmodel/tts.ts: console -> log.error/warn - bigmodel/dictionary/*.ts: console -> log.error/debug/info 客户端代码(browser、page.tsx)保留 console.error
This commit is contained in:
@@ -4,6 +4,9 @@ import { determineSemanticMapping } from "./stage2-semanticMapping";
|
|||||||
import { generateStandardForm } from "./stage3-standardForm";
|
import { generateStandardForm } from "./stage3-standardForm";
|
||||||
import { generateEntries } from "./stage4-entriesGeneration";
|
import { generateEntries } from "./stage4-entriesGeneration";
|
||||||
import { LookUpError } from "@/lib/errors";
|
import { LookUpError } from "@/lib/errors";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-orchestrator");
|
||||||
|
|
||||||
export async function executeDictionaryLookup(
|
export async function executeDictionaryLookup(
|
||||||
text: string,
|
text: string,
|
||||||
@@ -11,35 +14,31 @@ export async function executeDictionaryLookup(
|
|||||||
definitionLang: string
|
definitionLang: string
|
||||||
): Promise<ServiceOutputLookUp> {
|
): Promise<ServiceOutputLookUp> {
|
||||||
try {
|
try {
|
||||||
// ========== 阶段 1:输入分析 ==========
|
log.debug("[Stage 1] Starting input analysis");
|
||||||
console.log("[阶段1] 开始输入分析...");
|
|
||||||
const analysis = await analyzeInput(text);
|
const analysis = await analyzeInput(text);
|
||||||
|
|
||||||
// 代码层面验证:输入是否有效
|
|
||||||
if (!analysis.isValid) {
|
if (!analysis.isValid) {
|
||||||
console.log("[阶段1] 输入无效:", analysis.reason);
|
log.debug("[Stage 1] Invalid input", { reason: analysis.reason });
|
||||||
throw analysis.reason || "无效输入";
|
throw analysis.reason || "无效输入";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (analysis.isEmpty) {
|
if (analysis.isEmpty) {
|
||||||
console.log("[阶段1] 输入为空");
|
log.debug("[Stage 1] Empty input");
|
||||||
throw "输入为空";
|
throw "输入为空";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[阶段1] 输入分析完成:", analysis);
|
log.debug("[Stage 1] Analysis complete", { analysis });
|
||||||
|
|
||||||
// ========== 阶段 2:语义映射 ==========
|
log.debug("[Stage 2] Starting semantic mapping");
|
||||||
console.log("[阶段2] 开始语义映射...");
|
|
||||||
const semanticMapping = await determineSemanticMapping(
|
const semanticMapping = await determineSemanticMapping(
|
||||||
text,
|
text,
|
||||||
queryLang,
|
queryLang,
|
||||||
analysis.inputLanguage || text
|
analysis.inputLanguage || text
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("[阶段2] 语义映射完成:", semanticMapping);
|
log.debug("[Stage 2] Semantic mapping complete", { semanticMapping });
|
||||||
|
|
||||||
// ========== 阶段 3:生成标准形式 ==========
|
log.debug("[Stage 3] Generating standard form");
|
||||||
console.log("[阶段3] 开始生成标准形式...");
|
|
||||||
|
|
||||||
// 如果进行了语义映射,标准形式要基于映射后的结果
|
// 如果进行了语义映射,标准形式要基于映射后的结果
|
||||||
// 同时传递原始输入作为语义参考
|
// 同时传递原始输入作为语义参考
|
||||||
@@ -52,16 +51,14 @@ export async function executeDictionaryLookup(
|
|||||||
shouldUseMapping ? text : undefined // 如果进行了映射,传递原始输入作为语义参考
|
shouldUseMapping ? text : undefined // 如果进行了映射,传递原始输入作为语义参考
|
||||||
);
|
);
|
||||||
|
|
||||||
// 代码层面验证:标准形式不能为空
|
|
||||||
if (!standardFormResult.standardForm) {
|
if (!standardFormResult.standardForm) {
|
||||||
console.error("[阶段3] 标准形式为空");
|
log.error("[Stage 3] Standard form is empty");
|
||||||
throw "无法生成标准形式";
|
throw "无法生成标准形式";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[阶段3] 标准形式生成完成:", standardFormResult);
|
log.debug("[Stage 3] Standard form complete", { standardFormResult });
|
||||||
|
|
||||||
// ========== 阶段 4:生成词条 ==========
|
log.debug("[Stage 4] Generating entries");
|
||||||
console.log("[阶段4] 开始生成词条...");
|
|
||||||
const entriesResult = await generateEntries(
|
const entriesResult = await generateEntries(
|
||||||
standardFormResult.standardForm,
|
standardFormResult.standardForm,
|
||||||
queryLang,
|
queryLang,
|
||||||
@@ -71,19 +68,18 @@ export async function executeDictionaryLookup(
|
|||||||
: analysis.inputType
|
: analysis.inputType
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("[阶段4] 词条生成完成:", entriesResult);
|
log.debug("[Stage 4] Entries complete", { entriesResult });
|
||||||
|
|
||||||
// ========== 组装最终结果 ==========
|
|
||||||
const finalResult: ServiceOutputLookUp = {
|
const finalResult: ServiceOutputLookUp = {
|
||||||
standardForm: standardFormResult.standardForm,
|
standardForm: standardFormResult.standardForm,
|
||||||
entries: entriesResult.entries,
|
entries: entriesResult.entries,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("[完成] 词典查询成功");
|
log.info("Dictionary lookup completed successfully");
|
||||||
return finalResult;
|
return finalResult;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[错误] 词典查询失败:", error);
|
log.error("Dictionary lookup failed", { error });
|
||||||
|
|
||||||
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
||||||
throw new LookUpError(errorMessage);
|
throw new LookUpError(errorMessage);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getAnswer } from "../zhipu";
|
import { getAnswer } from "../zhipu";
|
||||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||||
import { InputAnalysisResult } from "./types";
|
import { InputAnalysisResult } from "./types";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-stage1");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段 1:输入解析与语言识别
|
* 阶段 1:输入解析与语言识别
|
||||||
@@ -59,7 +62,7 @@ export async function analyzeInput(text: string): Promise<InputAnalysisResult> {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("阶段1失败:", error);
|
log.error("Stage 1 failed", { error });
|
||||||
// 失败时抛出错误,包含 reason
|
// 失败时抛出错误,包含 reason
|
||||||
throw new Error("输入分析失败:无法识别输入类型或语言");
|
throw new Error("输入分析失败:无法识别输入类型或语言");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getAnswer } from "../zhipu";
|
import { getAnswer } from "../zhipu";
|
||||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||||
import { SemanticMappingResult } from "./types";
|
import { SemanticMappingResult } from "./types";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-stage2");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段 2:跨语言语义映射决策
|
* 阶段 2:跨语言语义映射决策
|
||||||
@@ -99,7 +102,7 @@ b) 输入是明确、基础、可词典化的语义概念
|
|||||||
reason: result.reason,
|
reason: result.reason,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("阶段2失败:", error);
|
log.error("Stage 2 failed", { error });
|
||||||
// 失败时直接抛出错误,让编排器返回错误响应
|
// 失败时直接抛出错误,让编排器返回错误响应
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getAnswer } from "../zhipu";
|
import { getAnswer } from "../zhipu";
|
||||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||||
import { StandardFormResult } from "./types";
|
import { StandardFormResult } from "./types";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-stage3");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段 3:standardForm 生成与规范化
|
* 阶段 3:standardForm 生成与规范化
|
||||||
@@ -90,7 +93,7 @@ ${originalInput ? `
|
|||||||
reason,
|
reason,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("阶段3失败:", error);
|
log.error("Stage 3 failed", { error });
|
||||||
// 失败时抛出错误
|
// 失败时抛出错误
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getAnswer } from "../zhipu";
|
import { getAnswer } from "../zhipu";
|
||||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||||
import { EntriesGenerationResult } from "./types";
|
import { EntriesGenerationResult } from "./types";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-stage4");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段 4:释义与词条生成
|
* 阶段 4:释义与词条生成
|
||||||
@@ -103,7 +106,7 @@ ${isWord ? `
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("阶段4失败:", error);
|
log.error("Stage 4 failed", { error });
|
||||||
throw error; // 阶段4失败应该返回错误,因为这个阶段是核心
|
throw error; // 阶段4失败应该返回错误,因为这个阶段是核心
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { getAnswer } from "../zhipu";
|
import { getAnswer } from "../zhipu";
|
||||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||||
import { LanguageDetectionResult, TranslationLLMResponse } from "./types";
|
import { LanguageDetectionResult, TranslationLLMResponse } from "./types";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("translator-orchestrator");
|
||||||
|
|
||||||
async function detectLanguage(text: string): Promise<LanguageDetectionResult> {
|
async function detectLanguage(text: string): Promise<LanguageDetectionResult> {
|
||||||
const prompt = `
|
const prompt = `
|
||||||
@@ -40,7 +43,7 @@ async function detectLanguage(text: string): Promise<LanguageDetectionResult> {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Language detection failed:", error);
|
log.error("Language detection failed", { error });
|
||||||
throw new Error("Failed to detect source language");
|
throw new Error("Failed to detect source language");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +85,7 @@ async function performTranslation(
|
|||||||
|
|
||||||
return result.trim();
|
return result.trim();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Translation failed:", error);
|
log.error("Translation failed", { error });
|
||||||
throw new Error("Translation failed");
|
throw new Error("Translation failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +124,7 @@ async function generateIPA(
|
|||||||
|
|
||||||
return result.trim();
|
return result.trim();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("IPA generation failed:", error);
|
log.error("IPA generation failed", { error });
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,24 +135,19 @@ export async function executeTranslation(
|
|||||||
needIpa: boolean
|
needIpa: boolean
|
||||||
): Promise<TranslationLLMResponse> {
|
): Promise<TranslationLLMResponse> {
|
||||||
try {
|
try {
|
||||||
console.log("[翻译] 开始翻译流程...");
|
log.debug("Starting translation", { sourceText, targetLanguage, needIpa });
|
||||||
console.log("[翻译] 源文本:", sourceText);
|
|
||||||
console.log("[翻译] 目标语言:", targetLanguage);
|
|
||||||
console.log("[翻译] 需要 IPA:", needIpa);
|
|
||||||
|
|
||||||
// Stage 1: Detect source language
|
log.debug("[Stage 1] Detecting source language");
|
||||||
console.log("[阶段1] 检测源语言...");
|
|
||||||
const detectionResult = await detectLanguage(sourceText);
|
const detectionResult = await detectLanguage(sourceText);
|
||||||
console.log("[阶段1] 检测结果:", detectionResult);
|
log.debug("[Stage 1] Detection result", { detectionResult });
|
||||||
|
|
||||||
// Stage 2: Perform translation
|
log.debug("[Stage 2] Performing translation");
|
||||||
console.log("[阶段2] 执行翻译...");
|
|
||||||
const translatedText = await performTranslation(
|
const translatedText = await performTranslation(
|
||||||
sourceText,
|
sourceText,
|
||||||
detectionResult.sourceLanguage,
|
detectionResult.sourceLanguage,
|
||||||
targetLanguage
|
targetLanguage
|
||||||
);
|
);
|
||||||
console.log("[阶段2] 翻译完成:", translatedText);
|
log.debug("[Stage 2] Translation complete", { translatedText });
|
||||||
|
|
||||||
// Validate translation result
|
// Validate translation result
|
||||||
if (!translatedText) {
|
if (!translatedText) {
|
||||||
@@ -161,12 +159,12 @@ export async function executeTranslation(
|
|||||||
let targetIpa: string | undefined;
|
let targetIpa: string | undefined;
|
||||||
|
|
||||||
if (needIpa) {
|
if (needIpa) {
|
||||||
console.log("[阶段3] 生成 IPA...");
|
log.debug("[Stage 3] Generating IPA");
|
||||||
sourceIpa = await generateIPA(sourceText, detectionResult.sourceLanguage);
|
sourceIpa = await generateIPA(sourceText, detectionResult.sourceLanguage);
|
||||||
console.log("[阶段3] 源文本 IPA:", sourceIpa);
|
log.debug("[Stage 3] Source IPA", { sourceIpa });
|
||||||
|
|
||||||
targetIpa = await generateIPA(translatedText, targetLanguage);
|
targetIpa = await generateIPA(translatedText, targetLanguage);
|
||||||
console.log("[阶段3] 目标文本 IPA:", targetIpa);
|
log.debug("[Stage 3] Target IPA", { targetIpa });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble final result
|
// Assemble final result
|
||||||
@@ -179,10 +177,10 @@ export async function executeTranslation(
|
|||||||
targetIpa,
|
targetIpa,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("[完成] 翻译流程成功");
|
log.info("Translation completed successfully");
|
||||||
return finalResult;
|
return finalResult;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[错误] 翻译失败:", error);
|
log.error("Translation failed", { error });
|
||||||
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
||||||
throw new Error(errorMessage);
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("tts");
|
||||||
|
|
||||||
|
|
||||||
// ==================== 类型定义 ====================
|
// ==================== 类型定义 ====================
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +151,7 @@ class QwenTTSService {
|
|||||||
return data;
|
return data;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('语音合成请求失败:', error);
|
log.error("TTS request failed", { error });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,11 +161,7 @@ export type TTS_SUPPORTED_LANGUAGES = 'Auto' | 'Chinese' | 'English' | 'German'
|
|||||||
export async function getTTSUrl(text: string, lang: TTS_SUPPORTED_LANGUAGES) {
|
export async function getTTSUrl(text: string, lang: TTS_SUPPORTED_LANGUAGES) {
|
||||||
try {
|
try {
|
||||||
if (!process.env.DASHSCORE_API_KEY) {
|
if (!process.env.DASHSCORE_API_KEY) {
|
||||||
console.warn(
|
log.warn("DASHSCORE_API_KEY not set");
|
||||||
`⚠️ 环境变量 DASHSCORE_API_KEY 未设置\n` +
|
|
||||||
` 请在 .env 文件中设置或直接传入API Key\n` +
|
|
||||||
` 获取API Key: https://help.aliyun.com/zh/model-studio/get-api-key`
|
|
||||||
);
|
|
||||||
throw "API Key设置错误";
|
throw "API Key设置错误";
|
||||||
}
|
}
|
||||||
const ttsService = new QwenTTSService(
|
const ttsService = new QwenTTSService(
|
||||||
@@ -176,7 +176,7 @@ export async function getTTSUrl(text: string, lang: TTS_SUPPORTED_LANGUAGES) {
|
|||||||
);
|
);
|
||||||
return result.output.audio.url;
|
return result.output.audio.url;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('TTS合成失败:', error instanceof Error ? error.message : error);
|
log.error("TTS synthesis failed", { error: error instanceof Error ? error.message : error });
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { auth } from "@/auth";
|
|||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { ValidateError } from "@/lib/errors";
|
import { ValidateError } from "@/lib/errors";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
import {
|
import {
|
||||||
ActionInputGetUserProfileByUsername,
|
ActionInputGetUserProfileByUsername,
|
||||||
ActionInputSignIn,
|
ActionInputSignIn,
|
||||||
@@ -23,6 +24,8 @@ import {
|
|||||||
// Re-export types for use in components
|
// Re-export types for use in components
|
||||||
export type { ActionOutputAuth, ActionOutputUserProfile } from "./auth-action-dto";
|
export type { ActionOutputAuth, ActionOutputUserProfile } from "./auth-action-dto";
|
||||||
|
|
||||||
|
const log = createLogger("auth-action");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign up action
|
* Sign up action
|
||||||
* Creates a new user account
|
* Creates a new user account
|
||||||
@@ -68,7 +71,7 @@ export async function actionSignUp(prevState: ActionOutputAuth | undefined, form
|
|||||||
message: e.message,
|
message: e.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.error("Sign up error:", e);
|
log.error("Sign up failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Registration failed. Please try again later.",
|
message: "Registration failed. Please try again later.",
|
||||||
@@ -121,7 +124,7 @@ export async function actionSignIn(_prevState: ActionOutputAuth | undefined, for
|
|||||||
message: e.message,
|
message: e.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.error("Sign in error:", e);
|
log.error("Sign in failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Sign in failed. Please check your credentials.",
|
message: "Sign in failed. Please check your credentials.",
|
||||||
@@ -144,7 +147,7 @@ export async function signOutAction() {
|
|||||||
if (e instanceof Error && e.message.includes('NEXT_REDIRECT')) {
|
if (e instanceof Error && e.message.includes('NEXT_REDIRECT')) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
console.error("Sign out error:", e);
|
log.error("Sign out failed", { error: e });
|
||||||
redirect("/login");
|
redirect("/login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,7 @@ export async function actionGetUserProfileByUsername(dto: ActionInputGetUserProf
|
|||||||
data: userProfile,
|
data: userProfile,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Get user profile error:", e);
|
log.error("Get user profile failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Failed to retrieve user profile",
|
message: "Failed to retrieve user profile",
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
import { ActionInputLookUpDictionary, ActionOutputLookUpDictionary, validateActionInputLookUpDictionary } from "./dictionary-action-dto";
|
import { ActionInputLookUpDictionary, ActionOutputLookUpDictionary, validateActionInputLookUpDictionary } from "./dictionary-action-dto";
|
||||||
import { ValidateError } from "@/lib/errors";
|
import { ValidateError } from "@/lib/errors";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
import { serviceLookUp } from "./dictionary-service";
|
import { serviceLookUp } from "./dictionary-service";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-action");
|
||||||
|
|
||||||
export const actionLookUpDictionary = async (dto: ActionInputLookUpDictionary): Promise<ActionOutputLookUpDictionary> => {
|
export const actionLookUpDictionary = async (dto: ActionInputLookUpDictionary): Promise<ActionOutputLookUpDictionary> => {
|
||||||
try {
|
try {
|
||||||
return {
|
return {
|
||||||
@@ -18,7 +21,7 @@ export const actionLookUpDictionary = async (dto: ActionInputLookUpDictionary):
|
|||||||
message: e.message
|
message: e.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(e);
|
log.error("Dictionary lookup failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { executeDictionaryLookup } from "@/lib/bigmodel/dictionary/orchestrator";
|
import { executeDictionaryLookup } from "@/lib/bigmodel/dictionary/orchestrator";
|
||||||
import { repoCreateLookUp, repoCreateLookUpWithItemAndEntries, repoSelectLastLookUpResult } from "./dictionary-repository";
|
import { repoCreateLookUp, repoCreateLookUpWithItemAndEntries, repoSelectLastLookUpResult } from "./dictionary-repository";
|
||||||
import { ServiceInputLookUp } from "./dictionary-service-dto";
|
import { ServiceInputLookUp } from "./dictionary-service-dto";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("dictionary-service");
|
||||||
|
|
||||||
export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
||||||
const {
|
const {
|
||||||
@@ -39,7 +42,7 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
|||||||
},
|
},
|
||||||
response.entries
|
response.entries
|
||||||
).catch(error => {
|
).catch(error => {
|
||||||
console.error('Failed to save dictionary data:', error);
|
log.error("Failed to save dictionary data", { error });
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@@ -51,7 +54,7 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
|||||||
definitionLang: definitionLang,
|
definitionLang: definitionLang,
|
||||||
dictionaryItemId: lastLookUpResult.id
|
dictionaryItemId: lastLookUpResult.id
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Failed to save dictionary data:', error);
|
log.error("Failed to save dictionary data", { error });
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
standardForm: lastLookUpResult.standardForm,
|
standardForm: lastLookUpResult.standardForm,
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { ValidateError } from "@/lib/errors";
|
import { ValidateError } from "@/lib/errors";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("folder-action");
|
||||||
import {
|
import {
|
||||||
ActionInputCreatePair,
|
ActionInputCreatePair,
|
||||||
ActionInputUpdatePairById,
|
ActionInputUpdatePairById,
|
||||||
@@ -68,7 +71,7 @@ export async function actionGetPairsByFolderId(folderId: number) {
|
|||||||
data: await repoGetPairsByFolderId(folderId)
|
data: await repoGetPairsByFolderId(folderId)
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -93,7 +96,7 @@ export async function actionUpdatePairById(id: number, dto: ActionInputUpdatePai
|
|||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -109,7 +112,7 @@ export async function actionGetUserIdByFolderId(folderId: number) {
|
|||||||
data: await repoGetUserIdByFolderId(folderId)
|
data: await repoGetUserIdByFolderId(folderId)
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -125,7 +128,7 @@ export async function actionGetFolderVisibility(folderId: number) {
|
|||||||
data: await repoGetFolderVisibility(folderId)
|
data: await repoGetFolderVisibility(folderId)
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -149,7 +152,7 @@ export async function actionDeleteFolderById(folderId: number) {
|
|||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -173,7 +176,7 @@ export async function actionDeletePairById(id: number) {
|
|||||||
message: 'success'
|
message: 'success'
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -189,7 +192,7 @@ export async function actionGetFoldersWithTotalPairsByUserId(id: string): Promis
|
|||||||
data: await repoGetFoldersWithTotalPairsByUserId(id)
|
data: await repoGetFoldersWithTotalPairsByUserId(id)
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -205,7 +208,7 @@ export async function actionGetFoldersByUserId(userId: string) {
|
|||||||
data: await repoGetFoldersByUserId(userId)
|
data: await repoGetFoldersByUserId(userId)
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -236,7 +239,7 @@ export async function actionCreatePair(dto: ActionInputCreatePair) {
|
|||||||
message: e.message
|
message: e.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -266,7 +269,7 @@ export async function actionCreateFolder(userId: string, folderName: string) {
|
|||||||
message: e.message
|
message: e.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -302,7 +305,7 @@ export async function actionRenameFolderById(id: number, newName: string) {
|
|||||||
message: e.message
|
message: e.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.'
|
message: 'Unknown error occured.'
|
||||||
@@ -332,7 +335,7 @@ export async function actionSetFolderVisibility(
|
|||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
@@ -352,7 +355,7 @@ export async function actionGetPublicFolders(): Promise<ActionOutputGetPublicFol
|
|||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
@@ -372,7 +375,7 @@ export async function actionSearchPublicFolders(query: string): Promise<ActionOu
|
|||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
@@ -411,7 +414,7 @@ export async function actionToggleFavorite(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
@@ -449,7 +452,7 @@ export async function actionCheckFavorite(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
@@ -487,7 +490,7 @@ export async function actionGetUserFavorites(): Promise<ActionOutputGetUserFavor
|
|||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
log.error("Operation failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Unknown error occured.',
|
message: 'Unknown error occured.',
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import {
|
|||||||
validateActionInputTranslateText,
|
validateActionInputTranslateText,
|
||||||
} from "./translator-action-dto";
|
} from "./translator-action-dto";
|
||||||
import { ValidateError } from "@/lib/errors";
|
import { ValidateError } from "@/lib/errors";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
import { serviceTranslateText } from "./translator-service";
|
import { serviceTranslateText } from "./translator-service";
|
||||||
import { getAnswer } from "@/lib/bigmodel/zhipu";
|
import { getAnswer } from "@/lib/bigmodel/zhipu";
|
||||||
|
|
||||||
|
const log = createLogger("translator-action");
|
||||||
|
|
||||||
export const actionTranslateText = async (
|
export const actionTranslateText = async (
|
||||||
dto: ActionInputTranslateText
|
dto: ActionInputTranslateText
|
||||||
): Promise<ActionOutputTranslateText> => {
|
): Promise<ActionOutputTranslateText> => {
|
||||||
@@ -25,7 +28,7 @@ export const actionTranslateText = async (
|
|||||||
message: e.message,
|
message: e.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(e);
|
log.error("Translation action failed", { error: e });
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Unknown error occurred.",
|
message: "Unknown error occurred.",
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { executeTranslation } from "@/lib/bigmodel/translator/orchestrator";
|
import { executeTranslation } from "@/lib/bigmodel/translator/orchestrator";
|
||||||
import { repoCreateTranslationHistory, repoSelectLatestTranslation } from "./translator-repository";
|
import { repoCreateTranslationHistory, repoSelectLatestTranslation } from "./translator-repository";
|
||||||
import { ServiceInputTranslateText, ServiceOutputTranslateText } from "./translator-service-dto";
|
import { ServiceInputTranslateText, ServiceOutputTranslateText } from "./translator-service-dto";
|
||||||
|
import { createLogger } from "@/lib/logger";
|
||||||
|
|
||||||
|
const log = createLogger("translator-service");
|
||||||
|
|
||||||
export const serviceTranslateText = async (
|
export const serviceTranslateText = async (
|
||||||
dto: ServiceInputTranslateText
|
dto: ServiceInputTranslateText
|
||||||
@@ -31,7 +34,7 @@ export const serviceTranslateText = async (
|
|||||||
sourceIpa: needIpa ? response.sourceIpa : undefined,
|
sourceIpa: needIpa ? response.sourceIpa : undefined,
|
||||||
targetIpa: needIpa ? response.targetIpa : undefined,
|
targetIpa: needIpa ? response.targetIpa : undefined,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error("Failed to save translation data:", error);
|
log.error("Failed to save translation data", { error });
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -54,7 +57,7 @@ export const serviceTranslateText = async (
|
|||||||
sourceIpa: lastTranslation.sourceIpa || undefined,
|
sourceIpa: lastTranslation.sourceIpa || undefined,
|
||||||
targetIpa: lastTranslation.targetIpa || undefined,
|
targetIpa: lastTranslation.targetIpa || undefined,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error("Failed to save translation data:", error);
|
log.error("Failed to save translation data", { error });
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user