🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🌐 chore: translate non-English comments to English in server file service (#10546)
LobeHub Bot08572d060270
diff --git a/src/server/services/file/impls/index.ts b/src/server/services/file/impls/index.tsindex bb08ce6ba8d..6d4f415a815 100644--- a/src/server/services/file/impls/index.ts+++ b/src/server/services/file/impls/index.ts@@ -5,11 +5,11 @@ import { S3StaticFileImpl } from './s3';import { FileServiceImpl } from './type';/**- * 创建文件服务模块- * 根据环境自动选择使用S3或桌面本地文件实现+ * Create file service module+ * Automatically selects between S3 or desktop local file implementation based on environment*/export const createFileServiceModule = (): FileServiceImpl => {- // 如果在桌面应用环境,使用本地文件实现+ // If in desktop application environment, use local file implementationif (isDesktop) {return new DesktopLocalFileImpl();}diff --git a/src/server/services/file/impls/local.ts b/src/server/services/file/impls/local.tsindex 03794b15eb8..f10113ccc7c 100644--- a/src/server/services/file/impls/local.ts+++ b/src/server/services/file/impls/local.ts@@ -12,12 +12,12 @@ import { extractKeyFromUrlOrReturnOriginal } from './utils';const log = debug('lobe-file:desktop-local');/**- * 桌面应用本地文件服务实现+ * Desktop application local file service implementation*/export class DesktopLocalFileImpl implements FileServiceImpl {/**- * 获取本地文件的URL- * 通过 IPC 从主进程获取 HTTP URL+ * Get local file URL+ * Retrieve HTTP URL from main process via IPC*/private async getLocalFileUrl(key: string): Promise<string> {try {@@ -29,16 +29,16 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 创建预签名上传URL(本地版实际上是直接返回文件路径,可能需要进一步扩展)+ * Create pre-signed upload URL (local version directly returns file path, may need further extension)*/async createPreSignedUrl(key: string): Promise<string> {- // 在桌面应用本地文件实现中,不需要预签名URL- // 直接返回文件路径+ // In desktop application local file implementation, pre-signed URL is not needed+ // Directly return the file pathreturn key;}/**- * 创建预签名预览URL(本地版是通过HTTP路径访问本地文件)+ * Create pre-signed preview URL (local version accesses local files via HTTP path)*/async createPreSignedUrlForPreview(key: string): Promise<string> {return this.getLocalFileUrl(key);@@ -49,13 +49,13 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 批量删除文件+ * Delete files in batch*/async deleteFiles(keys: string[]): Promise<any> {try {if (!keys || keys.length === 0) return { success: true };- // 确保所有路径都是合法的desktop://路径+ // Ensure all paths are valid desktop:// pathsconst invalidKeys = keys.filter((key) => !key.startsWith('desktop://'));if (invalidKeys.length > 0) {console.error('Invalid desktop file paths:', invalidKeys);@@ -65,7 +65,7 @@ export class DesktopLocalFileImpl implements FileServiceImpl {};}- // 使用electronIpcClient的专用方法+ // Use electronIpcClient's dedicated methodreturn await electronIpcClient.deleteFiles(keys);} catch (error) {console.error('Failed to delete files:', error);@@ -82,20 +82,20 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 获取文件字节数组+ * Get file byte array*/async getFileByteArray(key: string): Promise<Uint8Array> {try {- // 从Electron获取文件的绝对路径+ // Get absolute file path from Electronconst filePath = await electronIpcClient.getFilePathById(key);- // 检查文件是否存在+ // Check if file existsif (!existsSync(filePath)) {console.error(`File not found: ${filePath}`);return new Uint8Array();}- // 读取文件内容并转换为Uint8Array+ // Read file content and convert to Uint8Arrayconst buffer = readFileSync(filePath);return new Uint8Array(buffer);} catch (e) {@@ -105,20 +105,20 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 获取文件内容+ * Get file content*/async getFileContent(key: string): Promise<string> {try {- // 从Electron获取文件的绝对路径+ // Get absolute file path from Electronconst filePath = await electronIpcClient.getFilePathById(key);- // 检查文件是否存在+ // Check if file existsif (!existsSync(filePath)) {console.error(`File not found: ${filePath}`);return '';}- // 读取文件内容并转换为字符串+ // Read file content and convert to stringreturn readFileSync(filePath, 'utf8');} catch (e) {console.error('Failed to get file content:', e);@@ -127,7 +127,7 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 获取完整文件URL+ * Get full file URL*/async getFullFileUrl(url?: string | null): Promise<string> {if (!url) return '';@@ -139,32 +139,32 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 上传内容- * 注意:这个功能可能需要扩展Electron IPC接口+ * Upload content+ * Note: This feature may require extension of Electron IPC interface*/async uploadContent(filePath: string, content: string): Promise<any> {- // 这里需要扩展electronIpcClient以支持上传文件内容- // 例如: return electronIpcClient.uploadContent(filePath, content);+ // Need to extend electronIpcClient to support uploading file content+ // For example: return electronIpcClient.uploadContent(filePath, content);console.warn('uploadContent not implemented for Desktop local file service', filePath, content);return;}/**- * 从完整URL中提取key- * 从 HTTP URL 中提取 desktop:// 格式的路径+ * Extract key from full URL+ * Extract desktop:// format path from HTTP URL*/getKeyFromFullUrl(url: string): string {try {const urlObj = new URL(url);const pathSegments = urlObj.pathname.split('/').filter((segment) => segment !== '');- // 移除第一个路径段(desktop-file)+ // Remove first path segment (desktop-file)pathSegments.shift();- // 重新组合剩余的路径段+ // Recombine remaining path segmentsconst filePath = pathSegments.join('/');- // 返回 desktop:// 格式的路径+ // Return desktop:// format pathreturn `desktop://${filePath}`;} catch (e) {console.error('[DesktopLocalFileImpl] Failed to extract key from URL:', e);@@ -173,23 +173,23 @@ export class DesktopLocalFileImpl implements FileServiceImpl {}/**- * 上传媒体文件+ * Upload media file*/async uploadMedia(key: string, buffer: Buffer): Promise<{ key: string }> {try {- // 将 Buffer 转换为 Base64 字符串+ // Convert Buffer to Base64 stringconst content = buffer.toString('base64');- // 从 key 中提取文件名+ // Extract filename from keyconst filename = path.basename(key);- // 计算文件的 SHA256 hash+ // Calculate SHA256 hash of the fileconst hash = sha256(buffer);- // 根据文件URL推断 MIME 类型+ // Infer MIME type from file URLconst type = inferContentTypeFromImageUrl(key)!;- // 构造上传参数+ // Construct upload parametersconst uploadParams = {content,filename,@@ -198,7 +198,7 @@ export class DesktopLocalFileImpl implements FileServiceImpl {type,};- // 调用 electronIpcClient 上传文件+ // Call electronIpcClient to upload fileconst result = await electronIpcClient.createFile(uploadParams);if (!result.success) {diff --git a/src/server/services/file/impls/s3.ts b/src/server/services/file/impls/s3.tsindex de95df2ec57..72de8af80a6 100644--- a/src/server/services/file/impls/s3.ts+++ b/src/server/services/file/impls/s3.ts@@ -7,7 +7,7 @@ import { FileServiceImpl } from './type';import { extractKeyFromUrlOrReturnOriginal } from './utils';/**- * 基于S3的文件服务实现+ * S3-based file service implementation*/export class S3StaticFileImpl implements FileServiceImpl {private readonly s3: S3;diff --git a/src/server/services/file/impls/type.ts b/src/server/services/file/impls/type.tsindex 2ed072834ef..308d33a1918 100644--- a/src/server/services/file/impls/type.ts+++ b/src/server/services/file/impls/type.ts@@ -1,54 +1,54 @@/**- * S3文件服务实现+ * File service implementation interface*/export interface FileServiceImpl {/**- * 创建预签名上传URL+ * Create pre-signed upload URL*/createPreSignedUrl(key: string): Promise<string>;/**- * 创建预签名预览URL+ * Create pre-signed preview URL*/createPreSignedUrlForPreview(key: string, expiresIn?: number): Promise<string>;/**- * 删除文件+ * Delete file*/deleteFile(key: string): Promise<any>;/**- * 批量删除文件+ * Delete files in batch*/deleteFiles(keys: string[]): Promise<any>;/**- * 获取文件字节数组+ * Get file byte array*/getFileByteArray(key: string): Promise<Uint8Array>;/**- * 获取文件内容+ * Get file content*/getFileContent(key: string): Promise<string>;/**- * 获取完整文件URL+ * Get full file URL*/getFullFileUrl(url?: string | null, expiresIn?: number): Promise<string>;/**- * 从完整URL中提取key+ * Extract key from full URL*/getKeyFromFullUrl(url: string): string;/**- * 上传内容+ * Upload content*/uploadContent(path: string, content: string): Promise<any>;/**- * 上传媒体文件+ * Upload media file*/uploadMedia(key: string, buffer: Buffer): Promise<{ key: string }>;}diff --git a/src/server/services/file/index.ts b/src/server/services/file/index.tsindex 10c9e41a5b9..da4eb20193b 100644--- a/src/server/services/file/index.ts+++ b/src/server/services/file/index.ts@@ -11,8 +11,8 @@ import { TempFileManager } from '@/server/utils/tempFileManager';import { FileServiceImpl, createFileServiceModule } from './impls';/**- * 文件服务类- * 使用模块化实现方式,提供文件操作服务+ * File service class+ * Provides file operation services using a modular implementation approach*/export class FileService {private userId: string;@@ -26,70 +26,70 @@ export class FileService {}/**- * 删除文件+ * Delete file*/public async deleteFile(key: string) {return this.impl.deleteFile(key);}/**- * 批量删除文件+ * Delete files in batch*/public async deleteFiles(keys: string[]) {return this.impl.deleteFiles(keys);}/**- * 获取文件内容+ * Get file content*/public async getFileContent(key: string): Promise<string> {return this.impl.getFileContent(key);}/**- * 获取文件字节数组+ * Get file byte array*/public async getFileByteArray(key: string): Promise<Uint8Array> {return this.impl.getFileByteArray(key);}/**- * 创建预签名上传URL+ * Create pre-signed upload URL*/public async createPreSignedUrl(key: string): Promise<string> {return this.impl.createPreSignedUrl(key);}/**- * 创建预签名预览URL+ * Create pre-signed preview URL*/public async createPreSignedUrlForPreview(key: string, expiresIn?: number): Promise<string> {return this.impl.createPreSignedUrlForPreview(key, expiresIn);}/**- * 上传内容+ * Upload content*/public async uploadContent(path: string, content: string) {return this.impl.uploadContent(path, content);}/**- * 获取完整文件URL+ * Get full file URL*/public async getFullFileUrl(url?: string | null, expiresIn?: number): Promise<string> {return this.impl.getFullFileUrl(url, expiresIn);}/**- * 从完整 URL中 提取 key+ * Extract key from full URL*/public getKeyFromFullUrl(url: string): string {return this.impl.getKeyFromFullUrl(url);}/**- * 上传媒体文件+ * Upload media file*/public async uploadMedia(key: string, buffer: Buffer): Promise<{ key: string }> {return this.impl.uploadMedia(key, buffer);