diff --git a/.github/build-for-linux/Dockerfile b/.github/build-for-linux/Dockerfile deleted file mode 100644 index 326ba69..0000000 --- a/.github/build-for-linux/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM rust:buster -COPY entrypoint.sh /entrypoint.sh -RUN chmod a+x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/.github/build-for-linux/action.yml b/.github/build-for-linux/action.yml deleted file mode 100644 index a214161..0000000 --- a/.github/build-for-linux/action.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: 'Build for Linux' -branding: - icon: user-check - color: gray-dark -inputs: - target: - required: true - description: 'Rust Target' - toolchain: - required: true - description: 'Rust Toolchain' -runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.target }} - - ${{ inputs.toolchain }} \ No newline at end of file diff --git a/.github/build-for-linux/build.sh b/.github/build-for-linux/build.sh deleted file mode 100644 index c38d5d4..0000000 --- a/.github/build-for-linux/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -cargo build --target "$INPUT_TARGET" --release -mv target/$INPUT_TARGET/release/libplugin.so ./plugin.so diff --git a/.github/build-for-linux/entrypoint.sh b/.github/build-for-linux/entrypoint.sh deleted file mode 100644 index 93b25d8..0000000 --- a/.github/build-for-linux/entrypoint.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -rustup target add "$INPUT_TARGET" -rustup toolchain install --force-non-host "$INPUT_TOOLCHAIN" -apt-get install pkg-config - -if [ "$INPUT_TARGET" = "x86_64-unknown-linux-gnu" ]; then - apt-get update - apt-get install -y libssl-dev -elif [ "$INPUT_TARGET" = "i686-unknown-linux-gnu" ]; then - dpkg --add-architecture i386 - apt-get update - apt-get install -y libstdc++6:i386 libatomic1:i386 gcc-multilib g++-multilib libssl-dev:i386 - export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH - export PKG_CONFIG_SYSROOT_DIR=/ -elif [ "$INPUT_TARGET" = "aarch64-unknown-linux-gnu" ]; then - sed 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch-=amd64,i386] http:\/\/ports.ubuntu.com\/ubuntu-ports\//g' /etc/apt/sources.list | tee /etc/apt/sources.list.d/ports.list - sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list - dpkg --add-architecture arm64 - apt-get update - apt-get install -y libncurses6:arm64 libtinfo6:arm64 linux-libc-dev:arm64 libncursesw6:arm64 libcups2:arm64 - apt-get install -y --no-install-recommends g++-aarch64-linux-gnu libc6-dev-arm64-cross libssl-dev:arm64 - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc - export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc - export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ - export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig - export PKG_CONFIG_ALLOW_CROSS=1 -elif [ "$INPUT_TARGET" = "armv7-unknown-linux-gnueabihf" ]; then - sed 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch-=amd64,i386] http:\/\/ports.ubuntu.com\/ubuntu-ports\//g' /etc/apt/sources.list | tee /etc/apt/sources.list.d/ports.list - sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list - dpkg --add-architecture armhf - apt-get update - apt-get install -y libncurses6:armhf libtinfo6:armhf linux-libc-dev:armhf libncursesw6:armhf libcups2:armhf - apt-get install -y --no-install-recommends g++-arm-linux-gnueabihf libc6-dev-armhf-cross libssl-dev:armhf libwebkit2gtk-4.0-dev:armhf libgtk-3-dev:armhf patchelf:armhf librsvg2-dev:armhf - export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc - export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc - export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ - export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig - export PKG_CONFIG_ALLOW_CROSS=1 -else - echo "Unknown target: $INPUT_TARGET" && exit 1 -fi - -bash .github/build-for-linux/build.sh \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ebf1fa..4756390 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,10 +12,6 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 1 - - name: Install Rust Stable - uses: dtolnay/rust-toolchain@stable - - name: check - run: cargo check --all --all-targets - name: Install zip run: sudo apt-get install -y zip jq - id: getname @@ -28,12 +24,7 @@ jobs: fail-fast: false matrix: platform: [windows-latest] - target: - [ - x86_64-pc-windows-msvc, - i686-pc-windows-msvc, - aarch64-pc-windows-msvc, - ] + target: [x86_64-pc-windows-msvc] runs-on: ${{ matrix.platform }} steps: - name: Checkout @@ -48,102 +39,18 @@ jobs: rustup toolchain install --force-non-host stable-${{ matrix.target }} - name: Build run: cargo build --release --target ${{ matrix.target }} - - name: Rename - run: move target/${{ matrix.target }}/release/plugin.dll ./plugin.dll - - uses: vimtor/action-zip@v1 - with: - files: info.json ${{needs.check.outputs.icon}} plugin.dll - dest: ${{needs.check.outputs.name}}.potext - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.target }} - path: "*.potext" - if-no-files-found: error - - name: Wrap - if: startsWith(github.ref, 'refs/tags') - uses: vimtor/action-zip@v1 - with: - files: ${{needs.check.outputs.name}}.potext - dest: ${{ matrix.target }}.zip - - name: Upload Release - if: startsWith(github.ref, 'refs/tags') - uses: softprops/action-gh-release@v1 + - name: Download PaddleOCR-json + run: wget https://github.com/hiroi-sora/PaddleOCR-json/releases/download/v1.3.0/PaddleOCR-json_v.1.3.0.7z + - name: extract-7z-action + uses: DuckSoft/extract-7z-action@v1.0 with: - token: ${{ secrets.TOKEN }} - files: ${{ matrix.target }}.zip - build-for-macos: - needs: check - strategy: - fail-fast: false - matrix: - platform: [macos-latest] - target: [x86_64-apple-darwin, aarch64-apple-darwin] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Install Rust Stable - uses: dtolnay/rust-toolchain@stable - - name: install toolchain - run: | - rustup target add ${{ matrix.target }} - rustup toolchain install --force-non-host stable-${{ matrix.target }} - - name: Build - run: cargo build --release --target ${{ matrix.target }} + pathSource: PaddleOCR-json_v.1.3.0.7z + pathTarget: PPOCR/PaddleOCR-json_v.1.3.0 - name: Rename - run: sudo mv target/${{ matrix.target }}/release/libplugin.dylib ./plugin.dylib - - uses: vimtor/action-zip@v1 - with: - files: info.json ${{needs.check.outputs.icon}} plugin.dylib - dest: ${{needs.check.outputs.name}}.potext - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.target }} - path: "*.potext" - if-no-files-found: error - - name: Wrap - if: startsWith(github.ref, 'refs/tags') - uses: vimtor/action-zip@v1 - with: - files: ${{needs.check.outputs.name}}.potext - dest: ${{ matrix.target }}.zip - - name: Upload Release - if: startsWith(github.ref, 'refs/tags') - uses: softprops/action-gh-release@v1 - with: - token: ${{ secrets.TOKEN }} - files: ${{ matrix.target }}.zip - build-for-linux: - needs: check - strategy: - fail-fast: false - matrix: - platform: [ubuntu-latest] - target: - [ - x86_64-unknown-linux-gnu, - i686-unknown-linux-gnu, - aarch64-unknown-linux-gnu, - armv7-unknown-linux-gnueabihf, - ] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Build for Linux - uses: ./.github/build-for-linux - with: - target: ${{ matrix.target }} - toolchain: stable-${{ matrix.target }} + run: move target/${{ matrix.target }}/release/plugin.dll ./plugin.dll - uses: vimtor/action-zip@v1 with: - files: info.json ${{needs.check.outputs.icon}} plugin.so + files: info.json ${{needs.check.outputs.icon}} plugin.dll PPOCR dest: ${{needs.check.outputs.name}}.potext - name: Upload Artifacts uses: actions/upload-artifact@v3 diff --git a/Cargo.lock b/Cargo.lock index 8523aff..91b5911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,81 +2,12 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" - -[[package]] -name = "bumpalo" -version = "3.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" - -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - -[[package]] -name = "cc" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" -dependencies = [ - "libc", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -84,290 +15,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.4" +name = "dirs" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" - -[[package]] -name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "cfg-if", + "dirs-sys", ] [[package]] -name = "errno" -version = "0.3.2" +name = "dirs-sys" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ - "errno-dragonfly", "libc", + "option-ext", + "redox_users", "windows-sys", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "getrandom" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ - "cc", + "cfg-if", "libc", + "wasi", ] -[[package]] -name = "fastrand" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-core", - "futures-io", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.27.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" - -[[package]] -name = "h2" -version = "0.3.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2 0.4.9", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "ipnet" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" - [[package]] name = "itoa" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" -[[package]] -name = "js-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.147" @@ -375,178 +59,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] -name = "linux-raw-sys" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" - -[[package]] -name = "log" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" -dependencies = [ - "libc", - "wasi", - "windows-sys", -] - -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "openssl" -version = "0.10.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-src" -version = "111.27.0+1.1.1v" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e8f197c82d7511c5b014030c9b1efeda40d7d5f99d23b4ceed3524a5e63f02" -dependencies = [ - "cc", -] - -[[package]] -name = "openssl-sys" -version = "0.9.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" -dependencies = [ - "cc", - "libc", - "openssl-src", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkg-config" -version = "0.3.27" +name = "option-ext" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "plugin" version = "1.0.0" dependencies = [ - "openssl", - "reqwest", + "dirs", "serde_json", - "urlencoding", ] [[package]] @@ -569,67 +92,22 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] -name = "reqwest" -version = "0.11.18" +name = "redox_users" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustix" -version = "0.38.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" -dependencies = [ - "bitflags 2.3.3", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", + "getrandom", + "redox_syscall", + "thiserror", ] [[package]] @@ -638,38 +116,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "schannel" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.188" @@ -701,47 +147,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "socket2" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "syn" version = "2.0.28" @@ -754,262 +159,37 @@ dependencies = [ ] [[package]] -name = "tempfile" -version = "3.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" +name = "thiserror" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ - "tinyvec_macros", + "thiserror-impl", ] [[package]] -name = "tinyvec_macros" -version = "0.1.1" +name = "thiserror-impl" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "socket2 0.5.3", - "windows-sys", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" -dependencies = [ - "once_cell", + "proc-macro2", + "quote", + "syn", ] -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" - -[[package]] -name = "web-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.48.0" @@ -1075,12 +255,3 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" - -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] diff --git a/Cargo.toml b/Cargo.toml index 52b8671..2fd28f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,5 @@ edition = "2021" crate-type = ["dylib"] # pot只支持dylib类型动态库,请勿修改 [dependencies] -reqwest = {version="0.11.18",features = ["blocking","json"]} -urlencoding = "2.1.3" +dirs = "5.0.1" serde_json = "1.0" - -[target.'cfg(target_os = "linux")'.dependencies] -openssl={version="0.10",features=["vendored"]} diff --git a/README.md b/README.md index c0a9114..537388e 100644 --- a/README.md +++ b/README.md @@ -1,69 +1 @@ -# Pot-App 文字识别插件模板仓库 (以 [OCR Space](https://ocr.space/) 为例) - -### [English](./README_EN.md) | 简体中文 - -### 此仓库为模板仓库,编写插件时可以直接由此仓库创建插件仓库 - -## 插件编写指南 - -### 1. 插件仓库创建 - -- 以此仓库为模板创建一个新的仓库 -- 仓库名为 `pot-app-recognize-plugin-<插件名>`,例如 `pot-app-recognize-plugin-ocrspace` - -### 2. 插件信息配置 - -编辑 `info.json` 文件,修改以下字段: - -- `id`:插件唯一 id,必须以`[plugin]`开头,例如 `[plugin].com.pot-app.ocrspace` -- `display`: 插件显示名称,例如 `OCR Space` -- `homepage`: 插件主页,填写你的仓库地址即可,例如 `https://github.com/pot-app/pot-app-recognize-plugin-template` -- `icon`: 插件图标,填写当前目录下的图标名称,例如 `icon.png` -- `needs`: 插件依赖,一个数组,每个依赖为一个对象,包含以下字段: - - `key`: 依赖 key,对应该项依赖在配置文件中的名称,例如 `apikey` - - `display`: 依赖显示名称,对应用户显示的名称,例如 `API Key` -- `language`: 插件支持的语言映射,将 pot 的语言代码和插件发送请求时的语言代码一一对应 - -### 3. 插件编写/编译 - -编辑 `src/lib.rs` 实现 `recognize` 函数 - -#### Input parameters - -```rust - base64: &str, // 图像 Base64 - lang: &str, // 语言代码 - needs: HashMap, // 插件需要的其他配置信息,由info.json定义 -``` - -#### Return value - -```rust -// 返回用Value包裹的String - return Ok(Value::String(result)); -``` - -#### 测试/编译 - -```bash -cargo test --package plugin --lib -- tests --nocapture # 运行测试用例 -cargo build --release # 编译 -``` - -### 4. 打包 pot 插件 - -1. 在`target/release`目录找到`plugin.dll`(Windows)/`libplugin.dylib`(MacOS)/`libplugin.so`(Linux)文件,统一删除`lib`前缀. - -2. 将`plugin.dll`/`libplugin.dylib`/`libplugin.so`文件和`info.json`以及图标文件压缩为 zip 文件。 - -3. 将文件重命名为`<插件id>.potext`,例如`[plugin].com.pot-app.ocrspace.potext`,即可得到 pot 需要的插件。 - -## 自动编译打包 - -本仓库配置了 Github Actions,可以实现推送后自动编译打包插件。 - -每次将仓库推送到 GitHub 之后 actions 会自动运行,将打包好的插件上传到 artifact,在 actions 页面可以下载 - -每次提交 Tag 之后,actions 会自动运行,将打包好的插件上传到 release,在 release 页面可以下载打包好的插件 - -> 注意需要在仓库设置中添加一个名为`TOKEN`的 secret,值为一个有权限的 GitHub Token,用于上传 release +# Pot-App Paddle OCR 插件 (基于 [PaddleOCR-json](https://github.com/hiroi-sora/PaddleOCR-json)) diff --git a/README_EN.md b/README_EN.md deleted file mode 100644 index e90959e..0000000 --- a/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# Pot-App Text Recognize Plugin Template Repository (Take [OCR Space](https://ocr.space/) for example) - -### English | [简体中文](./README.md) - -### This repository is a template repository. You can directly create a plugin repository from this repository when writing plugins - -## Plugin Writing Guide - -### 1. Create a plugin repository - -- Create a new repository using this repository as a template -- Named `pot-app-recognize-plugin-`,Eg: `pot-app-recognize-plugin-ocrspace` - -### 2. Plugin information configuration - -Edit the `info.json` file and modify the following fields: - -- `id`: The unique ID of the plugin, which must start with `[plugin]`, for example `[plugin].com.pot-app.ocrspace` -- `homepage`: The homepage of the plugin, simply fill in your repository address, for example `https://github.com/pot-app/pot-app-recognize-plugin-template` -- `display`: The display name of the plugin, for example `OCR Space` -- `icon`: The icon of the plugin, for example `icon.png` -- `needs`: Dependencies required by the plugin. It is an array where each dependency is an object that includes the following fields: - - `key`: The key of the dependency, corresponding to its name in the configuration file. For example,`apikey`. - - `display`: The display name of the dependency as shown to users. For example,`API Key`. - - `language`: Mapping between language codes used in Pot and language codes used when sending requests to plugins. - -### 3. Plugin writing/compiling - -Edit `src/lib.rs` to implement `recognize` function - -#### Input parameters - -```rust - base64: &str, // base64 encoded image - lang: &str, // language code - needs: HashMap, // Additional configuration information required by the plugin, defined by info.json -``` - -#### Return value - -```rust -// Returns a String wrapped in Value - return Ok(Value::String(result)); -``` - -#### Test/Compile - -```bash -cargo test --package plugin --lib -- tests --nocapture # run the test case -cargo build --release # Compile -``` - -### 4. Package pot Plugin - -1. Find the `plugin.dll` (Windows)/`libplugin.dylib` (MacOS)/`libplugin.so` (Linux) file in the `target/release` directory and delete the prefix `lib`. - -2. Compress the `plugin.dll`/`libplugin.dylib`/`libplugin.so`, with the `info.json` and icon files, into a zip file. - -3. Rename the file as `.potext`, for example `[plugin].com.pot-app.ocrspace.potext`, to obtain the plugin required by pot. - -## Automatic Compilation and Package - -This repository is configured with Github Actions, which allows for automatic compilation and packaging of plugins after pushing. - -Every time the commit is pushed to GitHub, actions will run automatically and upload the packaged plugin to artifacts. The packaged plugin can be downloaded from the actions page. - -After each tag submission, actions will also run automatically and upload the packaged plugin to releases. The packaged plugin can be downloaded from the release page. - -> Please note that you need to add a secret named `TOKEN` in the repository settings. The value should be a GitHub Token with appropriate permissions, which will be used for uploading releases. diff --git a/icon.png b/icon.png deleted file mode 100644 index 790945f..0000000 Binary files a/icon.png and /dev/null differ diff --git a/info.json b/info.json index 923d084..9e1763c 100644 --- a/info.json +++ b/info.json @@ -1,10 +1,10 @@ { - "id": "[plugin].com.pot-app.ocrspace", + "id": "[plugin].com.pot-app.paddle", "plugin_type": "recognize", - "icon": "icon.png", - "display": "OCR Space", - "homepage": "https://github.com/pot-app/pot-app-recognize-plugin-template", - "needs": [{ "key": "apikey", "display": "Api Key" }], + "icon": "paddle.png", + "display": "Paddle OCR", + "homepage": "https://github.com/pot-app/pot-app-recognize-plugin-paddle", + "needs": [], "language": { "auto": "", "zh_cn": "", diff --git a/paddle.png b/paddle.png new file mode 100644 index 0000000..3339b90 Binary files /dev/null and b/paddle.png differ diff --git a/src/lib.rs b/src/lib.rs index 5a110f1..cbbdaa1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,48 +1,58 @@ -use serde_json::Value; +use dirs::{cache_dir, config_dir}; +use serde_json::{json, Value}; use std::collections::HashMap; use std::error::Error; +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; +use std::process::Command; #[no_mangle] pub fn recognize( - base64: &str, // 图像Base64 - lang: &str, // 识别语言 - // (pot会根据info.json 中的 language 字段传入插件需要的语言代码,无需再次转换) - needs: HashMap, // 插件需要的其他参数,由info.json定义 + _base64: &str, + _lang: &str, + _needs: HashMap, ) -> Result> { - let client = reqwest::blocking::ClientBuilder::new().build()?; - - let apikey = match needs.get("apikey") { - Some(apikey) => apikey.to_string(), - None => return Err("apikey not found".into()), - }; - - let base64 = format!("data:image/png;base64,{}", base64); - let mut form_data = HashMap::new(); - form_data.insert("base64Image", base64); - form_data.insert("OCREngine", "2".to_string()); - - let res: Value = client - .post("https://api.ocr.space/parse/image") - .header("apikey", apikey) - .header("content-type", "application/x-www-form-urlencoded") - .form(&form_data) - .send()? - .json()?; - - fn parse_result(res: Value) -> Option { - let result_list = res.as_object()?.get("ParsedResults")?.as_array()?; - let mut result = String::new(); - for i in result_list { - let parsed_text = i.as_object()?.get("ParsedText")?.as_str()?; - result.push_str(parsed_text); + let config_dir_path = config_dir().unwrap(); + + let plugin_path = config_dir_path + .join("com.pot-app.desktop") + .join("plugins") + .join("recognize") + .join("[plugin].com.pot-app.paddle"); + let paddle_dir_path = plugin_path.join("PaddleOCR-json_v.1.3.0"); + let paddle_exe_path = paddle_dir_path.join("PaddleOCR-json.exe"); + + let cache_dir_path = cache_dir().unwrap(); + let image_path = cache_dir_path + .join("com.pot-app.desktop") + .join("pot_screenshot_cut.png"); + + let mut cmd = Command::new("cmd"); + let cmd = cmd.creation_flags(0x08000000); + let cmd = cmd.args(["/c", &paddle_exe_path.to_str().unwrap()]); + + let output = cmd + .current_dir(paddle_dir_path) + .arg(&format!("--image_path={}", image_path.to_str().unwrap())) + .output()?; + + let result = String::from_utf8_lossy(&output.stdout); + let result = result.split("OCR init completed.\r\n").last().unwrap(); + let json = serde_json::from_str(result.trim())?; + + fn parse_json(res: Value) -> Option { + let mut target = String::new(); + let data = res.as_object()?.get("data")?.as_array()?; + for line in data { + let str = line.as_object()?.get("text")?.as_str()?; + target.push_str(str); + target.push_str("\n"); } - Some(result) + Some(target) } - - if let Some(result) = parse_result(res) { - return Ok(Value::String(result)); - } else { - return Err("Response Parse Error".into()); + match parse_json(json) { + Some(text) => Ok(Value::String(text)), + None => Err("Parse Error".into()), } } @@ -51,9 +61,8 @@ mod tests { use super::*; #[test] fn try_request() { - let mut needs = HashMap::new(); - needs.insert("apikey".to_string(), "".to_string()); - let result = recognize("iVBORw0KGgoAAAANSUhEUgAAADsAAAAeCAYAAACSRGY2AAAAAXNSR0IArs4c6QAAArNJREFUWEftl19IU1Ecxz+O5uQiNTCJkNj0ZWhkSOyh7CEy0CWZQQoTWYgvk17KFAdr9GBBYGb/qD0oUpgSCZViGkTRQ/hwEVOYIIhlMF8kUjbGZGPFdGtrGvcWzTa79/Gec+79fb7fc36/38nQ6/Xf+E+eDAV2mzqdns6WtDNRqYP5UQ71D8i2RoGVLdW/mqg4K6287G3sqHtEdYEP8clrdpZXYdCCxzWE/dkHjp5poXa/AMEVZodvU+ea2/Dn0n2NnK8wYsgVQAWEAng+TfHiZTddy75NI83LtdBRfSS2xruIONKNNftccs9sFPbLkpqcXUCmei1At2uO3YU6CKnR7AhDLDJ204bdH4u/tKSdjkodmvCrEKz6A2iE9fWEVhAftmF1JwBnmxm0msjPinzHH2A1U42GFcSJZYzGJCaodVhYnRqgZngUCmw8rStC419gzOnA7iuio8HG8b3wccTC2clIkFkWhppPkKcK4H7bTev7cWbDQ5kHcZxqorpQAO8M929dp+eHPgJtNXepNajh6wx9j+9E3BeoONBCc7mOnCx18rJxFDYGYmbwson85Sm67nXSB9SXO7loFPCIDzj2anwtdOPhTpxlueB+h7W3BzF+w6pM9F8wYxACTPc30jAfHTTR22ymeMP78HicEMkqPX8Ku5kAMV6Ba/VOKvQJu4GIkCzx5sYlWuOOxE8CphcsbBQxjBOFXeD5VQftiekr2aUnOc4qsNvV2W12ZuVlYx9irxWrO82zMXLqbFz5WseVqLNlOnKyU7DOhkP/qx2Uysf05BLFJVvQQf1uUxHdmIY9Fq5UxfW5wQCezxK9sbYKx+mTGPMi/fRW9cbSd4rUnyH71pP6KNIRKrDSGqXnDMXZ9PRNOmrF2USNtFotXq+XYDAoLV8Kz5DlrAKbwg7+KrTvuhRWXxXeDuUAAAAASUVORK5CYII=", "", needs).unwrap(); - println!("{result}"); + let needs = HashMap::new(); + let result = recognize("", "", needs); + println!("{result:?}"); } }