add patch

This commit is contained in:
beyondkmp 2025-09-02 09:57:38 +08:00
parent 6ae7a0c8ab
commit b0bf8ac17e
2 changed files with 22 additions and 134 deletions

View File

@ -1,142 +1,30 @@
diff --git a/index.js b/index.js
index dc071739e79876dff88e1be06a9168e294222d13..f3ac975e0ac74a1bd233f9e5136bee3e95003b6d 100644
index dc071739e79876dff88e1be06a9168e294222d13..b9df7525c62bdf777e89e732e1b0c81f84d872f2 100644
--- a/index.js
+++ b/index.js
@@ -196,127 +196,7 @@ function requireNative() {
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
}
} else if (process.platform === 'linux') {
- if (process.arch === 'x64') {
- if (isMusl()) {
- try {
- return require('./system-ocr.linux-x64-musl.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-x64-musl')
- } catch (e) {
- loadErrors.push(e)
- }
- } else {
- try {
- return require('./system-ocr.linux-x64-gnu.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-x64-gnu')
- } catch (e) {
- loadErrors.push(e)
- }
- }
- } else if (process.arch === 'arm64') {
- if (isMusl()) {
- try {
- return require('./system-ocr.linux-arm64-musl.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-arm64-musl')
- } catch (e) {
- loadErrors.push(e)
- }
- } else {
- try {
- return require('./system-ocr.linux-arm64-gnu.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-arm64-gnu')
- } catch (e) {
- loadErrors.push(e)
- }
- }
- } else if (process.arch === 'arm') {
- if (isMusl()) {
- try {
- return require('./system-ocr.linux-arm-musleabihf.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-arm-musleabihf')
- } catch (e) {
- loadErrors.push(e)
- }
- } else {
- try {
- return require('./system-ocr.linux-arm-gnueabihf.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-arm-gnueabihf')
- } catch (e) {
- loadErrors.push(e)
- }
- }
- } else if (process.arch === 'riscv64') {
- if (isMusl()) {
- try {
- return require('./system-ocr.linux-riscv64-musl.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-riscv64-musl')
- } catch (e) {
- loadErrors.push(e)
- }
- } else {
- try {
- return require('./system-ocr.linux-riscv64-gnu.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-riscv64-gnu')
- } catch (e) {
- loadErrors.push(e)
- }
- }
- } else if (process.arch === 'ppc64') {
- try {
- return require('./system-ocr.linux-ppc64-gnu.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-ppc64-gnu')
- } catch (e) {
- loadErrors.push(e)
- }
- } else if (process.arch === 's390x') {
- try {
- return require('./system-ocr.linux-s390x-gnu.node')
- } catch (e) {
- loadErrors.push(e)
- }
- try {
- return require('@napi-rs/system-ocr-linux-s390x-gnu')
- } catch (e) {
- loadErrors.push(e)
- }
- } else {
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
- }
+ return
} else if (process.platform === 'openharmony') {
if (process.arch === 'arm64') {
try {
@@ -380,7 +260,7 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
@@ -380,7 +380,7 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
}
}
-if (!nativeBinding) {
+if (!nativeBinding && (process.platform === 'darwin' || process.platform === 'win32')) {
+if (!nativeBinding && process.platform !== 'linux') {
if (loadErrors.length > 0) {
throw new Error(
`Cannot find native binding. ` +
@@ -392,6 +392,13 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}
-module.exports = nativeBinding
-module.exports.OcrAccuracy = nativeBinding.OcrAccuracy
-module.exports.recognize = nativeBinding.recognize
+if (process.platform === 'linux') {
+ module.exports = {OcrAccuracy: {
+ Fast: 0,
+ Accurate: 1
+ }, recognize: () => Promise.resolve({text: '', confidence: 1.0})}
+}else{
+ module.exports = nativeBinding
+ module.exports.OcrAccuracy = nativeBinding.OcrAccuracy
+ module.exports.recognize = nativeBinding.recognize
+}

View File

@ -4784,7 +4784,7 @@ __metadata:
"@napi-rs/system-ocr@patch:@napi-rs/system-ocr@npm%3A1.0.2#~/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch":
version: 1.0.2
resolution: "@napi-rs/system-ocr@patch:@napi-rs/system-ocr@npm%3A1.0.2#~/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch::version=1.0.2&hash=920d94"
resolution: "@napi-rs/system-ocr@patch:@napi-rs/system-ocr@npm%3A1.0.2#~/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch::version=1.0.2&hash=407396"
dependencies:
"@napi-rs/system-ocr-darwin-arm64": "npm:1.0.2"
"@napi-rs/system-ocr-darwin-x64": "npm:1.0.2"
@ -4799,7 +4799,7 @@ __metadata:
optional: true
"@napi-rs/system-ocr-win32-x64-msvc":
optional: true
checksum: 10c0/38e79196e700dbf572ab2f4f0f77926ab0412d4639af47cefe522bdf6dcdcf0bd81ae27a7490661dfb19efad0128d67cbf0a3dae34b287130b219987808cece0
checksum: 10c0/c1e336b3d506dd771c72b1bddc94e4a9ddeae5292222a7485d66dd0c11eed5d2a37cc7ea338f229e7d4abad276966658bdb4a2b322c9d6a0349dad6e65fcea51
languageName: node
linkType: hard