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
@@ -751,3 +751,48 @@ describe('extended-actions / get_rkey_server', () => {
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Wave 3: ocr_image / .ocr_image (OIDB 0xE07_0) ───
|
||||
|
||||
describe('extended-actions / ocr_image', () => {
|
||||
const ocrResult = { texts: [{ text: 'hello', confidence: 99, coordinates: [{ x: 1, y: 2 }] }], language: 'en' };
|
||||
|
||||
it('OCRs an http(s) image URL directly', async () => {
|
||||
const ocrImage = vi.fn(async () => ocrResult);
|
||||
const bridge = fakeBridge({ apis: { misc: { ocrImage } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('ocr_image', { image: 'https://x/a.jpg' });
|
||||
expect(res).toMatchObject({ status: 'ok', data: ocrResult });
|
||||
expect(ocrImage).toHaveBeenCalledWith('https://x/a.jpg');
|
||||
});
|
||||
|
||||
it('resolves a cached image file_id to a url via getImageInfo', async () => {
|
||||
const ocrImage = vi.fn(async () => ocrResult);
|
||||
const getImageInfo = vi.fn(async () => ({ url: 'https://cdn/resolved.jpg' }));
|
||||
const bridge = fakeBridge({ apis: { misc: { ocrImage } } });
|
||||
const res = await makeHandler(fakeCtx(bridge, { getImageInfo })).handle('ocr_image', { image: 'abc.jpg' });
|
||||
expect(res.status).toBe('ok');
|
||||
expect(ocrImage).toHaveBeenCalledWith('https://cdn/resolved.jpg');
|
||||
});
|
||||
|
||||
it('.ocr_image shares the same handler', async () => {
|
||||
const ocrImage = vi.fn(async () => ocrResult);
|
||||
const bridge = fakeBridge({ apis: { misc: { ocrImage } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('.ocr_image', { image: 'http://x/a.jpg' });
|
||||
expect(res.status).toBe('ok');
|
||||
});
|
||||
|
||||
it('fails when the id cannot be resolved to a url', async () => {
|
||||
const ocrImage = vi.fn();
|
||||
const getImageInfo = vi.fn(async () => null);
|
||||
const bridge = fakeBridge({ apis: { misc: { ocrImage } } });
|
||||
const res = await makeHandler(fakeCtx(bridge, { getImageInfo })).handle('ocr_image', { image: 'unknown' });
|
||||
expect(res.status).toBe('failed');
|
||||
expect(ocrImage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects missing image', async () => {
|
||||
const bridge = fakeBridge({ apis: { misc: { ocrImage: vi.fn() } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('ocr_image', {});
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user