下载时增加版本判断
This commit is contained in:
@ -3,13 +3,17 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
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`,
|
||||
}
|
||||
|
||||
function releaseVersion() { return require("../../package.json").releaseVersion }
|
||||
|
||||
function getURL(template: string) {
|
||||
const version = require("../../package.json").releaseVersion;
|
||||
|
||||
let platform = "";
|
||||
let arch = "";
|
||||
switch (os.platform()) {
|
||||
@ -30,7 +34,7 @@ function getURL(template: string) {
|
||||
throw new Error(`Unsupported architecture: ${os.arch()}, Please compile the addon yourself.`);
|
||||
}
|
||||
|
||||
return template.replaceAll("{{version}}", version).replaceAll("{{platform}}", platform).replaceAll("{{arch}}", arch);
|
||||
return template.replaceAll("{{version}}", releaseVersion()).replaceAll("{{platform}}", platform).replaceAll("{{arch}}", arch);
|
||||
}
|
||||
|
||||
async function getStream() {
|
||||
@ -48,7 +52,12 @@ async function getStream() {
|
||||
export async function downloadAddon(savename?: string) {
|
||||
const defaultAddon = path.resolve(process.cwd(), C("ADDON_PATH"));
|
||||
const saveName = savename ? path.resolve(path.dirname(defaultAddon), savename) : defaultAddon;
|
||||
if (fs.existsSync(saveName)) return saveName;
|
||||
if (fs.existsSync(saveName)) {
|
||||
try {
|
||||
const addon = require(saveName);
|
||||
if (addon.__release__ === releaseVersion()) return saveName;
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
await fs.promises.mkdir(path.dirname(saveName), { recursive: true });
|
||||
|
||||
|
@ -33,8 +33,9 @@ async function testImage() {
|
||||
}
|
||||
|
||||
async function testMovie() {
|
||||
await cv.downloadAddon();
|
||||
const cap = new cv.VideoCapture("test_data/movie.mp4");
|
||||
if(cap.grab()){
|
||||
if (cap.grab()) {
|
||||
const im = cap.retrieve();
|
||||
debugger;
|
||||
}
|
||||
|
Reference in New Issue
Block a user