feat(onebot): implement ocr_image via OIDB 0xE07_0
Server-side image OCR ported from Lagrange.Core ([Service] "OidbSvcTrpcTcp.0xe07_0") cross-checked with NapCat's Oidb.0xE07 proto (NapCat's transformer cmd 0xEB7 is a typo; the proto name + Lagrange + the wire name all say 0xE07_0). New ImageOcr service + proto types, misc.ocrImage api, and the ocr_image/.ocr_image action. The cmd takes an image URL, so the action accepts an http(s) url or a cached image file_id (resolved via getImageInfo); base64/local input is unsupported (NapCat's path is a Windows-only kernel OCR, not portable). Wire round-trip + response-parse tests lock the pb tags.
This commit is contained in:
8 files changed
+271
-3
No files matched your search
@@ -1248,12 +1248,34 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
// ocr_image — 服务端 OCR via OIDB 0xE07_0(port 自 Lagrange/NapCat proto)。
|
||||
// 该 cmd 接收图片 URL(服务端拉取),故 image 支持:http(s) URL 直用,或
|
||||
// 已缓存图片的 file_id(经 getImageInfo 解析出 URL)。base64/本地文件需先
|
||||
// 上传换 URL,本实现不覆盖(NapCat 走的是 Windows-only 内核 OCR,不可移植)。
|
||||
defineAction({
|
||||
name: ['ocr_image', '.ocr_image'],
|
||||
summary: 'OCR 图片(未实现)',
|
||||
summary: 'OCR 图片(服务端,需图片 URL 或已缓存的图片 file_id)',
|
||||
readOnly: true,
|
||||
params: {},
|
||||
run: () => failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented'),
|
||||
params: { image: f.string({ allowEmpty: false }) },
|
||||
run: async (p, ctx) => {
|
||||
let url = /^https?:\/\//i.test(p.image) ? p.image : '';
|
||||
if (!url) {
|
||||
const info = await ctx.getImageInfo(p.image);
|
||||
const resolved = info && typeof info.url === 'string' ? info.url : '';
|
||||
if (resolved) url = resolved;
|
||||
}
|
||||
if (!url) {
|
||||
return failedResponse(
|
||||
RETCODE.ACTION_FAILED,
|
||||
'ocr_image needs an http(s) image url or a cached image file_id; '
|
||||
+ 'base64/local-file input is not supported',
|
||||
);
|
||||
}
|
||||
const result = await ctx.bridge.apis.misc.ocrImage(url);
|
||||
// OcrResult is plain JSON data; the interface just lacks an index
|
||||
// signature, so coerce for the JsonValue-typed response.
|
||||
return okResponse(result as unknown as JsonObject);
|
||||
},
|
||||
}),
|
||||
|
||||
groupAction({
|
||||
|
||||
Reference in new issue
Block a user