feat: 更新资源管理器和协议处理逻辑,增强错误处理和缓存机制,优化CLI测试用例

This commit is contained in:
sean
2025-06-01 14:13:16 +08:00
parent 4a0ad6e61c
commit d8481b89bb
11 changed files with 198 additions and 513 deletions

View File

@ -25,13 +25,21 @@ class LearnCommand extends BasePouchCommand {
try {
// 直接使用ResourceManager解析资源
const content = await this.resourceManager.resolve(resourceUrl)
const result = await this.resourceManager.resolve(resourceUrl)
if (!result.success) {
return this.formatErrorResponse(resourceUrl, result.error.message)
}
// 解析协议信息
const urlMatch = resourceUrl.match(/^([a-zA-Z]+):\/\/(.+)$/)
const [, protocol, resourceId] = urlMatch
const urlMatch = resourceUrl.match(/^(@[!?]?)?([a-zA-Z][a-zA-Z0-9_-]*):\/\/(.+)$/)
if (!urlMatch) {
return this.formatErrorResponse(resourceUrl, '无效的资源URL格式')
}
const [, loadingSemantic, protocol, resourceId] = urlMatch
return this.formatSuccessResponse(protocol, resourceId, content)
return this.formatSuccessResponse(protocol, resourceId, result.content)
} catch (error) {
return this.formatErrorResponse(resourceUrl, error.message)
}