@w3vish/ffmpeg-installer
Advanced tools
+10
-0
| import { DownloadSource, PlatformInfo } from './types.js'; | ||
| /** | ||
| * Get user's home directory in a cross-platform way | ||
| */ | ||
| export declare function getUserHomeDir(): string; | ||
| /** | ||
| * Get application data directory based on platform | ||
| */ | ||
| export declare function getAppDataDir(): string; | ||
| export declare const APP_NAME = "ffmpeg-installer"; | ||
| export declare const BINARIES_DIR: string; | ||
| export declare const CONFIG_FILE_PATH: string; | ||
| export declare function ensureDirectoriesExist(): void; | ||
| /** | ||
@@ -5,0 +15,0 @@ * Supported platforms |
+41
-8
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| // Get the directory where the package is installed | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
| // Base directory for binaries | ||
| export const BINARIES_DIR = path.resolve(__dirname, '..', 'binaries'); | ||
| // Path to configuration file | ||
| export const CONFIG_FILE_PATH = path.resolve(__dirname, '..', 'config.json'); | ||
| import os from 'os'; | ||
| import fs from 'fs'; | ||
| /** | ||
| * Get user's home directory in a cross-platform way | ||
| */ | ||
| export function getUserHomeDir() { | ||
| return os.homedir(); | ||
| } | ||
| /** | ||
| * Get application data directory based on platform | ||
| */ | ||
| export function getAppDataDir() { | ||
| const homeDir = getUserHomeDir(); | ||
| // Platform-specific app data locations | ||
| switch (os.platform()) { | ||
| case 'win32': | ||
| return process.env.APPDATA || path.join(homeDir, 'AppData', 'Roaming'); | ||
| case 'darwin': | ||
| return path.join(homeDir, 'Library', 'Application Support'); | ||
| default: // Linux and others | ||
| return process.env.XDG_DATA_HOME || path.join(homeDir, '.local', 'share'); | ||
| } | ||
| } | ||
| // Define a consistent application name for storing data | ||
| export const APP_NAME = 'ffmpeg-installer'; | ||
| // Directory for storing FFmpeg binaries | ||
| export const BINARIES_DIR = path.join(getAppDataDir(), APP_NAME, 'binaries'); | ||
| // Path to the configuration file | ||
| export const CONFIG_FILE_PATH = path.join(getAppDataDir(), APP_NAME, 'config.json'); | ||
| // Make sure directories exist | ||
| export function ensureDirectoriesExist() { | ||
| const dirs = [ | ||
| path.dirname(CONFIG_FILE_PATH), | ||
| BINARIES_DIR | ||
| ]; | ||
| for (const dir of dirs) { | ||
| if (!fs.existsSync(dir)) { | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * Supported platforms | ||
@@ -12,0 +45,0 @@ */ |
+38
-33
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import axios from 'axios'; | ||
| import { CONFIG_FILE_PATH } from './constants.js'; | ||
| import { getPlatformDir } from './paths.js'; | ||
| import { CONFIG_FILE_PATH, BINARIES_DIR, ensureDirectoriesExist } from './constants.js'; | ||
| // Repository info for GitHub releases | ||
@@ -10,2 +9,31 @@ const GITHUB_REPO = 'w3vish/ffmpeg-installer'; | ||
| /** | ||
| * Ensure a directory exists | ||
| * @param dirPath Path to the directory | ||
| */ | ||
| async function ensureDir(dirPath) { | ||
| try { | ||
| // Check if directory exists | ||
| try { | ||
| const stats = fs.statSync(dirPath); | ||
| if (stats.isDirectory()) { | ||
| return; // Directory already exists | ||
| } | ||
| // If it exists but is not a directory, we have a problem | ||
| throw new Error(`Path exists but is not a directory: ${dirPath}`); | ||
| } | ||
| catch (err) { | ||
| // ENOENT means the directory doesn't exist, which is fine | ||
| if (err.code !== 'ENOENT') { | ||
| throw err; | ||
| } | ||
| } | ||
| // Create the directory recursively | ||
| console.log(`Creating directory: ${dirPath}`); | ||
| fs.mkdirSync(dirPath, { recursive: true }); | ||
| } | ||
| catch (err) { | ||
| throw new Error(`Failed to create directory ${dirPath}: ${err.message}`); | ||
| } | ||
| } | ||
| /** | ||
| * Download a file from a URL with progress tracking | ||
@@ -78,31 +106,2 @@ */ | ||
| /** | ||
| * Ensure a directory exists | ||
| * @param dirPath Path to the directory | ||
| */ | ||
| async function ensureDir(dirPath) { | ||
| try { | ||
| // Check if directory exists | ||
| try { | ||
| const stats = fs.statSync(dirPath); | ||
| if (stats.isDirectory()) { | ||
| return; // Directory already exists | ||
| } | ||
| // If it exists but is not a directory, we have a problem | ||
| throw new Error(`Path exists but is not a directory: ${dirPath}`); | ||
| } | ||
| catch (err) { | ||
| // ENOENT means the directory doesn't exist, which is fine | ||
| if (err.code !== 'ENOENT') { | ||
| throw err; | ||
| } | ||
| } | ||
| // Create the directory recursively | ||
| console.log(`Creating directory: ${dirPath}`); | ||
| fs.mkdirSync(dirPath, { recursive: true }); | ||
| } | ||
| catch (err) { | ||
| throw new Error(`Failed to create directory ${dirPath}: ${err.message}`); | ||
| } | ||
| } | ||
| /** | ||
| * Make a file executable | ||
@@ -132,5 +131,13 @@ * @param filePath Path to the file | ||
| /** | ||
| * Get the platform directory | ||
| */ | ||
| function getPlatformDir(platformIdentifier) { | ||
| return path.join(BINARIES_DIR, platformIdentifier); | ||
| } | ||
| /** | ||
| * Download and install binaries for a specific platform from GitHub releases | ||
| */ | ||
| export async function downloadBinaries(platformIdentifier, installOptions = { ffmpeg: true, ffprobe: true }) { | ||
| // Ensure all directories exist | ||
| ensureDirectoriesExist(); | ||
| const platformDir = getPlatformDir(platformIdentifier); | ||
@@ -183,3 +190,2 @@ // Ensure platform directory exists | ||
| try { | ||
| await ensureDir(path.dirname(CONFIG_FILE_PATH)); | ||
| if (fs.existsSync(CONFIG_FILE_PATH)) { | ||
@@ -223,4 +229,3 @@ const configData = fs.readFileSync(CONFIG_FILE_PATH, 'utf8'); | ||
| // Save updated config | ||
| await ensureDir(path.dirname(CONFIG_FILE_PATH)); | ||
| fs.writeFileSync(CONFIG_FILE_PATH, JSON.stringify(config, null, 2), 'utf8'); | ||
| } |
+12
-6
@@ -0,13 +1,19 @@ | ||
| // index.ts | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { BINARIES_DIR, CONFIG_FILE_PATH } from './constants.js'; | ||
| import { getCurrentPlatform } from './paths.js'; | ||
| // Get the directory where the package is installed | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
| import { CONFIG_FILE_PATH, BINARIES_DIR, ensureDirectoriesExist, SUPPORTED_PLATFORMS } from './constants.js'; | ||
| /** | ||
| * Get the current platform information | ||
| */ | ||
| function getCurrentPlatform() { | ||
| const platform = process.platform; | ||
| const arch = process.arch; | ||
| return SUPPORTED_PLATFORMS.find(p => p.platform === platform && p.arch === arch) || null; | ||
| } | ||
| /** | ||
| * Get the installed FFmpeg binaries for the current platform | ||
| */ | ||
| function getInstalledBinaries() { | ||
| // Ensure directories exist | ||
| ensureDirectoriesExist(); | ||
| const currentPlatform = getCurrentPlatform(); | ||
@@ -14,0 +20,0 @@ if (!currentPlatform) { |
+44
-3
| #!/usr/bin/env node | ||
| import os from 'os'; | ||
| import { CONFIG_FILE_PATH } from './constants.js'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { CONFIG_FILE_PATH, SUPPORTED_PLATFORMS, ensureDirectoriesExist } from './constants.js'; | ||
| import { downloadBinaries } from './downloader.js'; | ||
| import { getCurrentPlatform } from './paths.js'; | ||
| import { verifyConfig, createInitialConfig } from './verify.js'; | ||
| import readline from 'readline'; | ||
| /** | ||
| * Get the current platform information | ||
| */ | ||
| function getCurrentPlatform() { | ||
| const platform = process.platform; | ||
| const arch = process.arch; | ||
| return SUPPORTED_PLATFORMS.find(p => p.platform === platform && p.arch === arch) || null; | ||
| } | ||
| /** | ||
| * Verify if config file exists and is valid | ||
| */ | ||
| function verifyConfig(configPath) { | ||
| try { | ||
| if (!fs.existsSync(configPath)) { | ||
| return false; | ||
| } | ||
| const configData = fs.readFileSync(configPath, 'utf8'); | ||
| const config = JSON.parse(configData); | ||
| // Basic validation | ||
| return typeof config === 'object' && config !== null && typeof config.platforms === 'object'; | ||
| } | ||
| catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| /** | ||
| * Create initial config file | ||
| */ | ||
| async function createInitialConfig(configPath) { | ||
| const config = { | ||
| platforms: {}, | ||
| lastUpdated: new Date().toISOString() | ||
| }; | ||
| const configDir = path.dirname(configPath); | ||
| if (!fs.existsSync(configDir)) { | ||
| fs.mkdirSync(configDir, { recursive: true }); | ||
| } | ||
| fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8'); | ||
| } | ||
| /** | ||
| * Main installation function | ||
@@ -13,2 +52,4 @@ */ | ||
| try { | ||
| // Ensure all directories exist | ||
| ensureDirectoriesExist(); | ||
| // Create initial config file if it doesn't exist | ||
@@ -15,0 +56,0 @@ if (!verifyConfig(CONFIG_FILE_PATH)) { |
+4
-7
| { | ||
| "name": "@w3vish/ffmpeg-installer", | ||
| "version": "2.1.0", | ||
| "version": "2.2.1", | ||
| "type": "module", | ||
@@ -18,3 +18,3 @@ "description": "A fast and lightweight cross-platform FFmpeg & FFprobe binary installer for Node.js, supporting Linux, macOS, and Windows.", | ||
| "bin": { | ||
| "ffmpeg-installer": "./dist/installer.js" | ||
| "ffmpeg-installer": "dist/installer.js" | ||
| }, | ||
@@ -40,10 +40,7 @@ "files": [ | ||
| ], | ||
| "author": { | ||
| "name": "w3vish", | ||
| "url": "https://github.com/w3vish" | ||
| }, | ||
| "author": "w3vish (https://github.com/w3vish)", | ||
| "license": "ISC", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/w3vish/ffmpeg-installer" | ||
| "url": "git+https://github.com/w3vish/ffmpeg-installer.git" | ||
| }, | ||
@@ -50,0 +47,0 @@ "bugs": { |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
48934
5.72%1288
7.96%11
57.14%