完善预编译库下载工具

This commit is contained in:
2025-03-21 12:34:44 +08:00
parent 049a70afc2
commit f343d28540
3 changed files with 26 additions and 26 deletions

View File

@ -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<string, Record<string, string>> = {
"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() {