From f343d28540929035f646bc762a1671714a2d31f4 Mon Sep 17 00:00:00 2001 From: yizhi <946185759@qq.com> Date: Fri, 21 Mar 2025 12:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A2=84=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=BA=93=E4=B8=8B=E8=BD=BD=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/cv/download.ts | 42 +++++++++++++++++++----------------------- thirdpart/install.js | 8 ++++++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index d2ec11b..43320a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yizhi/cv", - "version": "1.0.3", + "version": "1.0.4", "releaseVersion": "1.0.3", "main": "dist/index.js", "types": "typing/index.d.ts", diff --git a/src/cv/download.ts b/src/cv/download.ts index bf59425..087f5c0 100644 --- a/src/cv/download.ts +++ b/src/cv/download.ts @@ -6,35 +6,31 @@ import { C } from "./common"; const URLS = { - GITHUB: `https://github.com/kangkang520/node-addons/releases/download/cv{{version}}/cv_{{platform}}_{{arch}}.node`, - URNAS: `http://git.urnas.cn:5200/yizhi-js-lib/opencv/releases/download/{{version}}/cv_{{platform}}_{{arch}}.node`, + GITHUB: `https://github.com/kangkang520/node-addons/releases/download/cv{{version}}/{{filename}}`, + URNAS: `http://git.urnas.cn:5200/yizhi-js-lib/opencv/releases/download/{{version}}/{{filename}}`, } function releaseVersion() { return require("../../package.json").releaseVersion } function getURL(template: string) { + const URL_CONFIG: Record> = { + "win32": { + "x64": "cv_windows_x64.node", + }, + "linux": { + "x64": "cv_linux_x64.node", + "arm64": "cv_linux_arm64.node", + }, + "darwin": { + "arm64": "cv_macos_arm64.node" + } + }; - let platform = ""; - let arch = ""; - switch (os.platform()) { - case "win32": - platform = "windows"; - break; - case "linux": - platform = "linux"; - break; - default: - throw new Error(`Unsupported platform: ${os.platform()}, Please compile the addon yourself.`); - } - switch (os.arch()) { - case "x64": - arch = "x64"; - break; - default: - throw new Error(`Unsupported architecture: ${os.arch()}, Please compile the addon yourself.`); - } - - return template.replaceAll("{{version}}", releaseVersion()).replaceAll("{{platform}}", platform).replaceAll("{{arch}}", arch); + const archConfig = URL_CONFIG[os.platform()]; + if (!archConfig) throw new Error(`Unsupported platform: ${os.platform()}`); + const downloadName = archConfig[os.arch()]; + if (!downloadName) throw new Error(`Unsupported architecture: ${os.arch()}`); + return template.replaceAll("{{version}}", releaseVersion()).replaceAll("{{filename}}", downloadName); } async function getStream() { diff --git a/thirdpart/install.js b/thirdpart/install.js index b580c38..c4c5535 100644 --- a/thirdpart/install.js +++ b/thirdpart/install.js @@ -140,7 +140,6 @@ async function downloadFromURL(name, url, resolver) { fs.rmSync(outputDir, { recursive: true, force: true }); } - async function main() { //OpenCV if (buildOptions.withOpenCV) cmakeBuildFromSource("OpenCV", "https://github.com/opencv/opencv.git", "4.11.0", null, [ @@ -155,7 +154,12 @@ async function main() { "-DBUILD_FAT_JAVA_LIB=OFF", "-DBUILD_ANDROID_SERVICE=OFF", "-DBUILD_JAVA=OFF", - "-DBUILD_PERF_TESTS=OFF" + "-DBUILD_PERF_TESTS=OFF", + "-DBUILD_TIFF=ON", + "-DBUILD_OPENJPEG=ON", + "-DBUILD_JPEG=ON", + "-DBUILD_PNG=ON", + "-DBUILD_WEBP=ON", ], (root) => [ `set(OpenCV_STATIC ON)`, os.platform() == "win32" ?