-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface ImageOcrResult { | ||
texts: TextDetection[]; | ||
language: string; | ||
} | ||
|
||
export interface TextDetection { | ||
text: string; | ||
confidence: number; | ||
coordinates: Coordinate[]; | ||
} | ||
|
||
export interface Coordinate { | ||
x: number; | ||
y: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as proto from "@/core/packet/transformer/proto"; | ||
import { NapProtoMsg } from "@napneko/nap-proto-core"; | ||
import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; | ||
import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; | ||
|
||
class ImageOCR extends PacketTransformer<typeof proto.OidbSvcTrpcTcp0xE07_0_Response> { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
build(url: string): OidbPacket { | ||
const body = new NapProtoMsg(proto.OidbSvcTrpcTcp0xE07_0).encode( | ||
{ | ||
version: 1, | ||
client: 0, | ||
entrance: 1, | ||
ocrReqBody: { | ||
imageUrl: url, | ||
originMd5: "", | ||
afterCompressMd5: "", | ||
afterCompressFileSize: "", | ||
afterCompressWeight: "", | ||
afterCompressHeight: "", | ||
isCut: false, | ||
} | ||
} | ||
); | ||
return OidbBase.build(0XEB7, 1, body, false, false); | ||
} | ||
|
||
parse(data: Buffer) { | ||
const base = OidbBase.parse(data); | ||
return new NapProtoMsg(proto.OidbSvcTrpcTcp0xE07_0_Response).decode(base.body); | ||
} | ||
} | ||
|
||
export default new ImageOCR(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as proto from "@/core/packet/transformer/proto"; | ||
import { NapProtoEncodeStructType, NapProtoMsg } from "@napneko/nap-proto-core"; | ||
import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; | ||
import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; | ||
import { IndexNode } from "@/core/packet/transformer/proto"; | ||
|
||
class DownloadImage extends PacketTransformer<typeof proto.NTV2RichMediaResp> { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
build(selfUid: string, node: NapProtoEncodeStructType<typeof IndexNode>): OidbPacket { | ||
const body = new NapProtoMsg(proto.NTV2RichMediaReq).encode({ | ||
reqHead: { | ||
common: { | ||
requestId: 1, | ||
command: 100 | ||
}, | ||
scene: { | ||
requestType: 2, | ||
businessType: 1, | ||
sceneType: 1, | ||
c2C: { | ||
accountType: 2, | ||
targetUid: selfUid | ||
}, | ||
}, | ||
client: { | ||
agentType: 2, | ||
} | ||
}, | ||
download: { | ||
node: node, | ||
download: { | ||
video: { | ||
busiType: 0, | ||
sceneType: 0 | ||
} | ||
} | ||
} | ||
}); | ||
return OidbBase.build(0x11C5, 200, body, true, false); | ||
} | ||
|
||
parse(data: Buffer) { | ||
const oidbBody = OidbBase.parse(data).body; | ||
return new NapProtoMsg(proto.NTV2RichMediaResp).decode(oidbBody); | ||
} | ||
} | ||
|
||
export default new DownloadImage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; | ||
|
||
export const OidbSvcTrpcTcp0xE07_0 = { | ||
version: ProtoField(1, ScalarType.UINT32), | ||
client: ProtoField(2, ScalarType.UINT32), | ||
entrance: ProtoField(3, ScalarType.UINT32), | ||
ocrReqBody: ProtoField(10, () => OcrReqBody, true), | ||
}; | ||
|
||
export const OcrReqBody = { | ||
imageUrl: ProtoField(1, ScalarType.STRING), | ||
languageType: ProtoField(2, ScalarType.UINT32), | ||
scene: ProtoField(3, ScalarType.UINT32), | ||
originMd5: ProtoField(10, ScalarType.STRING), | ||
afterCompressMd5: ProtoField(11, ScalarType.STRING), | ||
afterCompressFileSize: ProtoField(12, ScalarType.STRING), | ||
afterCompressWeight: ProtoField(13, ScalarType.STRING), | ||
afterCompressHeight: ProtoField(14, ScalarType.STRING), | ||
isCut: ProtoField(15, ScalarType.BOOL), | ||
}; | ||
|
||
export const OidbSvcTrpcTcp0xE07_0_Response = { | ||
retCode: ProtoField(1, ScalarType.INT32), | ||
errMsg: ProtoField(2, ScalarType.STRING), | ||
wording: ProtoField(3, ScalarType.STRING), | ||
ocrRspBody: ProtoField(10, () => OcrRspBody), | ||
}; | ||
|
||
export const OcrRspBody = { | ||
textDetections: ProtoField(1, () => TextDetection, false, true), | ||
language: ProtoField(2, ScalarType.STRING), | ||
requestId: ProtoField(3, ScalarType.STRING), | ||
ocrLanguageList: ProtoField(101, ScalarType.STRING, false, true), | ||
dstTranslateLanguageList: ProtoField(102, ScalarType.STRING, false, true), | ||
languageList: ProtoField(103, () => Language, false, true), | ||
afterCompressWeight: ProtoField(111, ScalarType.UINT32), | ||
afterCompressHeight: ProtoField(112, ScalarType.UINT32), | ||
}; | ||
|
||
export const TextDetection = { | ||
detectedText: ProtoField(1, ScalarType.STRING), | ||
confidence: ProtoField(2, ScalarType.UINT32), | ||
polygon: ProtoField(3, () => Polygon), | ||
advancedInfo: ProtoField(4, ScalarType.STRING), | ||
}; | ||
|
||
export const Polygon = { | ||
coordinates: ProtoField(1, () => Coordinate, false, true), | ||
}; | ||
|
||
export const Coordinate = { | ||
x: ProtoField(1, ScalarType.INT32), | ||
y: ProtoField(2, ScalarType.INT32), | ||
}; | ||
|
||
export const Language = { | ||
languageCode: ProtoField(1, ScalarType.STRING), | ||
languageDesc: ProtoField(2, ScalarType.STRING), | ||
}; |