mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-30 21:49:04 +08:00
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { checkFileExist, uriToLocalFile } from 'napcat-common/src/file';
|
|
import fs from 'fs';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { GeneralCallResultStatus } from 'napcat-core';
|
|
|
|
const SchemaData = Type.Object({
|
|
image: Type.String(),
|
|
});
|
|
|
|
type Payload = Static<typeof SchemaData>;
|
|
|
|
class OCRImageBase extends OneBotAction<Payload, GeneralCallResultStatus> {
|
|
override payloadSchema = SchemaData;
|
|
|
|
async _handle (payload: Payload) {
|
|
const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image);
|
|
if (!success) {
|
|
throw new Error(`OCR ${payload.image}失败, image字段可能格式不正确`);
|
|
}
|
|
if (path) {
|
|
try {
|
|
await checkFileExist(path, 5000); // 避免崩溃
|
|
const ret = await this.core.apis.SystemApi.ocrImage(path);
|
|
if (!ret) {
|
|
throw new Error(`OCR ${payload.image}失败`);
|
|
}
|
|
return ret.result;
|
|
} finally {
|
|
fs.unlink(path, () => { });
|
|
}
|
|
}
|
|
throw new Error(`OCR ${payload.image}失败, 文件可能不存在`);
|
|
}
|
|
}
|
|
|
|
export class OCRImage extends OCRImageBase {
|
|
override actionName = ActionName.OCRImage;
|
|
}
|
|
|
|
export class IOCRImage extends OCRImageBase {
|
|
override actionName = ActionName.IOCRImage;
|
|
}
|