Fix addon path resolution and error handling

Corrects the construction of the ffmpeg addon filename and improves error handling when the addon is not found. Also simplifies the isAvailable method by removing redundant existence checks.
This commit is contained in:
手瓜一十雪 2025-10-30 22:13:57 +08:00
parent a7b30ef844
commit ffe54af8d9

View File

@ -20,9 +20,9 @@ function getAddonPath(binaryPath: string): string {
const archName = arch(); const archName = arch();
let addonFileName: string = process.platform + '.' + process.arch; let addonFileName: string = process.platform + '.' + process.arch;
let addonPath = path.join(binaryPath, "./native/ffmpeg/", `${addonFileName}.node`); let addonPath = path.join(binaryPath, "./native/ffmpeg/", `ffmpegAddon.${addonFileName}.node`);
if (existsSync(addonPath)) { if (!existsSync(addonPath)) {
throw new Error(`Unsupported platform: ${platformName} ${archName}`); throw new Error(`Unsupported platform: ${platformName} ${archName} - Addon not found at ${addonPath}`);
} }
return addonPath; return addonPath;
} }
@ -44,12 +44,8 @@ export class FFmpegAddonAdapter implements IFFmpegAdapter {
*/ */
async isAvailable(): Promise<boolean> { async isAvailable(): Promise<boolean> {
try { try {
const addonPath = getAddonPath(this.binaryPath);
if (!existsSync(addonPath)) {
return false;
}
let temp_addon = { exports: {} }; let temp_addon = { exports: {} };
dlopen(temp_addon, addonPath); dlopen(temp_addon, getAddonPath(this.binaryPath));
this.addon = temp_addon.exports as FFmpeg; this.addon = temp_addon.exports as FFmpeg;
return this.addon !== null; return this.addon !== null;
} catch (error) { } catch (error) {