MCPcopy
hub / github.com/ZToolsCenter/ZTools / _getPluginDoc

Method _getPluginDoc

src/main/api/shared/database.ts:596–633  ·  view source on GitHub ↗

* 获取指定插件的文档或附件内容(供内部调用)

(
    pluginName: string,
    key: string
  )

Source from the content-addressed store, hash-verified

594 * 获取指定插件的文档或附件内容(供内部调用)
595 */
596 private async _getPluginDoc(
597 pluginName: string,
598 key: string
599 ): Promise<{ success: boolean; data?: any; type?: string; error?: string }> {
600 try {
601 const target = this.resolvePluginDataTarget(pluginName)
602 if (!target) {
603 return { success: false, error: '插件标识无效' }
604 }
605 const docId = `${target.prefix}${key}`
606
607 // 先尝试从主数据库获取
608 const doc = lmdbInstance.get(docId)
609 if (doc) {
610 return { success: true, data: doc, type: 'document' }
611 }
612
613 // 尝试从附件数据库获取
614 const attachmentDb = lmdbInstance.getAttachmentDb()
615 const metadataStr = attachmentDb.get(`attachment-ext:${docId}`)
616 if (metadataStr) {
617 const metadata = JSON.parse(metadataStr)
618 return {
619 success: true,
620 data: {
621 _id: docId,
622 ...metadata
623 },
624 type: 'attachment'
625 }
626 }
627
628 return { success: false, error: '文档不存在' }
629 } catch (error: unknown) {
630 console.error('[Database] 获取插件文档失败:', error)
631 return { success: false, error: error instanceof Error ? error.message : String(error) }
632 }
633 }
634
635 /**
636 * 清空指定插件的所有数据(供内部调用)

Callers 2

setupIPCMethod · 0.95
getPluginDocMethod · 0.95

Calls 3

getAttachmentDbMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected