MCPcopy Create free account
hub / github.com/experdot/pointer / AttachmentHandler

Class AttachmentHandler

src/main/attachmentHandler.ts:16–174  ·  view source on GitHub ↗

* 附件处理器 * 管理文件附件的本地存储

Source from the content-addressed store, hash-verified

14 * 管理文件附件的本地存储
15 */
16class AttachmentHandler {
17 /**
18 * 保存附件到本地
19 * @param fileId 文件ID
20 * @param fileName 文件名
21 * @param base64Content base64编码的文件内容
22 * @param pageId 页面ID(可选)
23 * @param messageId 消息ID(可选)
24 * @returns 相对路径
25 */
26 async saveAttachment(
27 fileId: string,
28 fileName: string,
29 base64Content: string,
30 pageId?: string,
31 messageId?: string
32 ): Promise<{ success: boolean; localPath?: string; error?: string }> {
33 try {
34 const relativePath = await saveAttachmentFile({
35 fileId,
36 fileName,
37 base64Content,
38 pageId,
39 messageId
40 })
41 return { success: true, localPath: relativePath }
42 } catch (error) {
43 console.error('保存附件失败:', error)
44 return {
45 success: false,
46 error: error instanceof Error ? error.message : '保存附件失败'
47 }
48 }
49 }
50
51 /**
52 * 读取附件内容
53 * @param localPath 相对路径
54 * @returns base64编码的内容
55 */
56 async readAttachment(
57 localPath: string
58 ): Promise<{ success: boolean; content?: string; error?: string }> {
59 try {
60 const content = await readAttachmentFile(localPath)
61 return { success: true, content }
62 } catch (error) {
63 console.error('读取附件失败:', error)
64 return {
65 success: false,
66 error: error instanceof Error ? error.message : '读取附件失败'
67 }
68 }
69 }
70
71 /**
72 * 删除附件
73 * @param localPath 相对路径

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected