@mediaproc/image 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/affine.d.ts +1 -0
- package/dist/commands/affine.d.ts.map +1 -1
- package/dist/commands/affine.js +8 -10
- package/dist/commands/affine.js.map +1 -1
- package/dist/commands/auto-enhance.d.ts +1 -0
- package/dist/commands/auto-enhance.d.ts.map +1 -1
- package/dist/commands/auto-enhance.js +7 -10
- package/dist/commands/auto-enhance.js.map +1 -1
- package/dist/commands/auto-orient.d.ts +1 -0
- package/dist/commands/auto-orient.d.ts.map +1 -1
- package/dist/commands/auto-orient.js +8 -10
- package/dist/commands/auto-orient.js.map +1 -1
- package/dist/commands/batch.d.ts +1 -0
- package/dist/commands/batch.d.ts.map +1 -1
- package/dist/commands/batch.js +5 -7
- package/dist/commands/batch.js.map +1 -1
- package/dist/commands/blur.d.ts +1 -0
- package/dist/commands/blur.d.ts.map +1 -1
- package/dist/commands/blur.js +8 -11
- package/dist/commands/blur.js.map +1 -1
- package/dist/commands/boolean.d.ts +1 -0
- package/dist/commands/boolean.d.ts.map +1 -1
- package/dist/commands/boolean.js +8 -11
- package/dist/commands/boolean.js.map +1 -1
- package/dist/commands/border.d.ts +1 -0
- package/dist/commands/border.d.ts.map +1 -1
- package/dist/commands/border.js +7 -10
- package/dist/commands/border.js.map +1 -1
- package/dist/commands/clahe.d.ts +1 -0
- package/dist/commands/clahe.d.ts.map +1 -1
- package/dist/commands/clahe.js +7 -10
- package/dist/commands/clahe.js.map +1 -1
- package/dist/commands/composite.d.ts +1 -0
- package/dist/commands/composite.d.ts.map +1 -1
- package/dist/commands/composite.js +7 -11
- package/dist/commands/composite.js.map +1 -1
- package/dist/commands/convert.d.ts +1 -0
- package/dist/commands/convert.d.ts.map +1 -1
- package/dist/commands/convert.js +7 -11
- package/dist/commands/convert.js.map +1 -1
- package/dist/commands/convolve.d.ts +1 -0
- package/dist/commands/convolve.d.ts.map +1 -1
- package/dist/commands/convolve.js +7 -10
- package/dist/commands/convolve.js.map +1 -1
- package/dist/commands/crop.d.ts +1 -0
- package/dist/commands/crop.d.ts.map +1 -1
- package/dist/commands/crop.js +8 -10
- package/dist/commands/crop.js.map +1 -1
- package/dist/commands/dilate.d.ts +1 -0
- package/dist/commands/dilate.d.ts.map +1 -1
- package/dist/commands/dilate.js +8 -10
- package/dist/commands/dilate.js.map +1 -1
- package/dist/commands/dominant-color.d.ts +1 -0
- package/dist/commands/dominant-color.d.ts.map +1 -1
- package/dist/commands/dominant-color.js +4 -5
- package/dist/commands/dominant-color.js.map +1 -1
- package/dist/commands/erode.d.ts +1 -0
- package/dist/commands/erode.d.ts.map +1 -1
- package/dist/commands/erode.js +8 -10
- package/dist/commands/erode.js.map +1 -1
- package/dist/commands/extend.d.ts +1 -0
- package/dist/commands/extend.d.ts.map +1 -1
- package/dist/commands/extend.js +8 -10
- package/dist/commands/extend.js.map +1 -1
- package/dist/commands/extract.d.ts +1 -0
- package/dist/commands/extract.d.ts.map +1 -1
- package/dist/commands/extract.js +7 -11
- package/dist/commands/extract.js.map +1 -1
- package/dist/commands/flatten.d.ts +1 -0
- package/dist/commands/flatten.d.ts.map +1 -1
- package/dist/commands/flatten.js +8 -10
- package/dist/commands/flatten.js.map +1 -1
- package/dist/commands/flip.d.ts +1 -0
- package/dist/commands/flip.d.ts.map +1 -1
- package/dist/commands/flip.js +8 -10
- package/dist/commands/flip.js.map +1 -1
- package/dist/commands/flop.d.ts +1 -0
- package/dist/commands/flop.d.ts.map +1 -1
- package/dist/commands/flop.js +8 -10
- package/dist/commands/flop.js.map +1 -1
- package/dist/commands/gamma.d.ts +1 -0
- package/dist/commands/gamma.d.ts.map +1 -1
- package/dist/commands/gamma.js +8 -10
- package/dist/commands/gamma.js.map +1 -1
- package/dist/commands/grayscale.d.ts +1 -0
- package/dist/commands/grayscale.d.ts.map +1 -1
- package/dist/commands/grayscale.js +8 -10
- package/dist/commands/grayscale.js.map +1 -1
- package/dist/commands/grid.d.ts +1 -0
- package/dist/commands/grid.d.ts.map +1 -1
- package/dist/commands/grid.js +3 -3
- package/dist/commands/grid.js.map +1 -1
- package/dist/commands/linear.d.ts +1 -0
- package/dist/commands/linear.d.ts.map +1 -1
- package/dist/commands/linear.js +8 -10
- package/dist/commands/linear.js.map +1 -1
- package/dist/commands/median.d.ts +1 -0
- package/dist/commands/median.d.ts.map +1 -1
- package/dist/commands/median.js +8 -10
- package/dist/commands/median.js.map +1 -1
- package/dist/commands/metadata-cmd.d.ts +1 -0
- package/dist/commands/metadata-cmd.d.ts.map +1 -1
- package/dist/commands/metadata-cmd.js +6 -8
- package/dist/commands/metadata-cmd.js.map +1 -1
- package/dist/commands/mirror.d.ts +1 -0
- package/dist/commands/mirror.d.ts.map +1 -1
- package/dist/commands/mirror.js +7 -11
- package/dist/commands/mirror.js.map +1 -1
- package/dist/commands/modulate.d.ts +1 -0
- package/dist/commands/modulate.d.ts.map +1 -1
- package/dist/commands/modulate.js +8 -10
- package/dist/commands/modulate.js.map +1 -1
- package/dist/commands/negate.d.ts +1 -0
- package/dist/commands/negate.d.ts.map +1 -1
- package/dist/commands/negate.js +8 -10
- package/dist/commands/negate.js.map +1 -1
- package/dist/commands/normalize.d.ts +1 -0
- package/dist/commands/normalize.d.ts.map +1 -1
- package/dist/commands/normalize.js +8 -10
- package/dist/commands/normalize.js.map +1 -1
- package/dist/commands/optimize.d.ts +1 -0
- package/dist/commands/optimize.d.ts.map +1 -1
- package/dist/commands/optimize.js +8 -10
- package/dist/commands/optimize.js.map +1 -1
- package/dist/commands/palette.d.ts +1 -0
- package/dist/commands/palette.d.ts.map +1 -1
- package/dist/commands/palette.js +5 -6
- package/dist/commands/palette.js.map +1 -1
- package/dist/commands/pixelate.d.ts +1 -0
- package/dist/commands/pixelate.d.ts.map +1 -1
- package/dist/commands/pixelate.js +7 -10
- package/dist/commands/pixelate.js.map +1 -1
- package/dist/commands/recomb.d.ts +1 -0
- package/dist/commands/recomb.d.ts.map +1 -1
- package/dist/commands/recomb.js +8 -10
- package/dist/commands/recomb.js.map +1 -1
- package/dist/commands/resize.d.ts +1 -0
- package/dist/commands/resize.d.ts.map +1 -1
- package/dist/commands/resize.js +9 -16
- package/dist/commands/resize.js.map +1 -1
- package/dist/commands/rotate.d.ts +1 -0
- package/dist/commands/rotate.d.ts.map +1 -1
- package/dist/commands/rotate.js +8 -10
- package/dist/commands/rotate.js.map +1 -1
- package/dist/commands/sepia.d.ts +1 -0
- package/dist/commands/sepia.d.ts.map +1 -1
- package/dist/commands/sepia.js +7 -10
- package/dist/commands/sepia.js.map +1 -1
- package/dist/commands/sharpen.d.ts +1 -0
- package/dist/commands/sharpen.d.ts.map +1 -1
- package/dist/commands/sharpen.js +8 -10
- package/dist/commands/sharpen.js.map +1 -1
- package/dist/commands/smart-crop.d.ts +1 -0
- package/dist/commands/smart-crop.d.ts.map +1 -1
- package/dist/commands/smart-crop.js +7 -11
- package/dist/commands/smart-crop.js.map +1 -1
- package/dist/commands/split.d.ts +1 -0
- package/dist/commands/split.d.ts.map +1 -1
- package/dist/commands/split.js +9 -9
- package/dist/commands/split.js.map +1 -1
- package/dist/commands/stack.d.ts +1 -0
- package/dist/commands/stack.d.ts.map +1 -1
- package/dist/commands/stack.js +3 -3
- package/dist/commands/stack.js.map +1 -1
- package/dist/commands/stats.d.ts +1 -0
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +4 -5
- package/dist/commands/stats.js.map +1 -1
- package/dist/commands/threshold.d.ts +1 -0
- package/dist/commands/threshold.d.ts.map +1 -1
- package/dist/commands/threshold.js +8 -10
- package/dist/commands/threshold.js.map +1 -1
- package/dist/commands/thumbnail.d.ts +1 -0
- package/dist/commands/thumbnail.d.ts.map +1 -1
- package/dist/commands/thumbnail.js +8 -10
- package/dist/commands/thumbnail.js.map +1 -1
- package/dist/commands/tint.d.ts +1 -0
- package/dist/commands/tint.d.ts.map +1 -1
- package/dist/commands/tint.js +8 -10
- package/dist/commands/tint.js.map +1 -1
- package/dist/commands/trim.d.ts +1 -0
- package/dist/commands/trim.d.ts.map +1 -1
- package/dist/commands/trim.js +8 -10
- package/dist/commands/trim.js.map +1 -1
- package/dist/commands/unflatten.d.ts +1 -0
- package/dist/commands/unflatten.d.ts.map +1 -1
- package/dist/commands/unflatten.js +8 -10
- package/dist/commands/unflatten.js.map +1 -1
- package/dist/commands/vignette.d.ts +1 -0
- package/dist/commands/vignette.d.ts.map +1 -1
- package/dist/commands/vignette.js +7 -10
- package/dist/commands/vignette.js.map +1 -1
- package/dist/commands/watermark.d.ts +1 -0
- package/dist/commands/watermark.d.ts.map +1 -1
- package/dist/commands/watermark.js +8 -11
- package/dist/commands/watermark.js.map +1 -1
- package/dist/utils/pathValidator.d.ts +33 -59
- package/dist/utils/pathValidator.d.ts.map +1 -1
- package/dist/utils/pathValidator.js +121 -146
- package/dist/utils/pathValidator.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Supported image file extensions
|
|
5
|
+
*/
|
|
6
|
+
export const IMAGE_EXTENSIONS = [
|
|
7
|
+
'.jpg',
|
|
8
|
+
'.jpeg',
|
|
9
|
+
'.png',
|
|
10
|
+
'.gif',
|
|
11
|
+
'.bmp',
|
|
12
|
+
'.webp',
|
|
13
|
+
'.tiff',
|
|
14
|
+
'.tif',
|
|
15
|
+
'.svg',
|
|
16
|
+
'.ico',
|
|
17
|
+
'.heic',
|
|
18
|
+
'.heif',
|
|
19
|
+
'.avif',
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Parse input path and return array of files
|
|
5
23
|
* Supports:
|
|
6
|
-
* - Single file: "
|
|
7
|
-
* - Multiple files: "
|
|
8
|
-
* -
|
|
9
|
-
* - Mixed: "photo.jpg,./photos/,another.jpg"
|
|
24
|
+
* - Single file: "image.jpg"
|
|
25
|
+
* - Multiple files with commas: "image1.jpg,image2.jpg,image3.jpg"
|
|
26
|
+
* - Directory: "input-images/" (finds all matching files)
|
|
10
27
|
*/
|
|
11
|
-
export function parseInputPaths(inputPath,
|
|
12
|
-
const
|
|
13
|
-
// Split by comma
|
|
14
|
-
const paths = inputPath.split(',').map(p => p.trim())
|
|
15
|
-
const allFiles = [];
|
|
28
|
+
export function parseInputPaths(inputPath, allowedExtensions = IMAGE_EXTENSIONS) {
|
|
29
|
+
const files = [];
|
|
30
|
+
// Split by comma for multiple files
|
|
31
|
+
const paths = inputPath.split(',').map(p => p.trim());
|
|
16
32
|
for (const p of paths) {
|
|
17
33
|
const resolvedPath = path.resolve(p);
|
|
18
34
|
// Check if path exists
|
|
@@ -21,188 +37,147 @@ export function parseInputPaths(inputPath, options = {}) {
|
|
|
21
37
|
}
|
|
22
38
|
const stats = fs.statSync(resolvedPath);
|
|
23
39
|
if (stats.isFile()) {
|
|
24
|
-
// Check if file
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
// Check if file has allowed extension
|
|
41
|
+
const ext = path.extname(resolvedPath).toLowerCase();
|
|
42
|
+
if (allowedExtensions.includes(ext)) {
|
|
43
|
+
files.push(resolvedPath);
|
|
27
44
|
}
|
|
28
45
|
}
|
|
29
46
|
else if (stats.isDirectory()) {
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
recursive,
|
|
34
|
-
maxDepth,
|
|
35
|
-
});
|
|
36
|
-
allFiles.push(...filesInDir);
|
|
47
|
+
// Recursively find all files in directory
|
|
48
|
+
const dirFiles = findFilesInDirectory(resolvedPath, allowedExtensions);
|
|
49
|
+
files.push(...dirFiles);
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
|
-
|
|
40
|
-
return [...new Set(allFiles)];
|
|
52
|
+
return files;
|
|
41
53
|
}
|
|
42
54
|
/**
|
|
43
|
-
*
|
|
55
|
+
* Recursively find all files with allowed extensions in a directory
|
|
44
56
|
*/
|
|
45
|
-
|
|
46
|
-
const { allowedExtensions, recursive = true, maxDepth = 10 } = options;
|
|
47
|
-
if (currentDepth > maxDepth) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
57
|
+
function findFilesInDirectory(dir, allowedExtensions) {
|
|
50
58
|
const files = [];
|
|
51
59
|
try {
|
|
52
|
-
const entries = fs.readdirSync(
|
|
60
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
53
61
|
for (const entry of entries) {
|
|
54
|
-
const fullPath = path.join(
|
|
55
|
-
if (entry.
|
|
56
|
-
//
|
|
57
|
-
|
|
62
|
+
const fullPath = path.join(dir, entry.name);
|
|
63
|
+
if (entry.isDirectory()) {
|
|
64
|
+
// Recursively search subdirectories
|
|
65
|
+
files.push(...findFilesInDirectory(fullPath, allowedExtensions));
|
|
66
|
+
}
|
|
67
|
+
else if (entry.isFile()) {
|
|
68
|
+
const ext = path.extname(fullPath).toLowerCase();
|
|
69
|
+
if (allowedExtensions.includes(ext)) {
|
|
58
70
|
files.push(fullPath);
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
|
-
else if (entry.isDirectory() && recursive) {
|
|
62
|
-
// Recursively search subdirectories
|
|
63
|
-
const subFiles = findFilesInDirectory(fullPath, options, currentDepth + 1);
|
|
64
|
-
files.push(...subFiles);
|
|
65
|
-
}
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
catch (error) {
|
|
69
|
-
// Ignore
|
|
76
|
+
// Ignore directories that can't be read
|
|
70
77
|
}
|
|
71
78
|
return files;
|
|
72
79
|
}
|
|
73
80
|
/**
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* Resolve output paths for input files
|
|
82
|
+
*
|
|
83
|
+
* Logic:
|
|
84
|
+
* 1. Single file + output has extension (e.g., output.jpg) = Use exact file path
|
|
85
|
+
* 2. Multiple files + output has extension = Invalid (error)
|
|
86
|
+
* 3. No output provided = Use current directory
|
|
87
|
+
* 4. Output directory provided = Use that directory
|
|
88
|
+
*
|
|
89
|
+
* @param inputFiles - Array of input file paths
|
|
90
|
+
* @param outputPath - Output path (file or directory, or undefined for current dir)
|
|
91
|
+
* @param suffix - Suffix to add to filenames (default: empty)
|
|
92
|
+
* @param newExtension - New extension for output files (default: same as input)
|
|
85
93
|
*/
|
|
86
|
-
export function
|
|
94
|
+
export function resolveOutputPaths(inputFiles, outputPath, options = {}) {
|
|
95
|
+
const { suffix = '', newExtension } = options;
|
|
96
|
+
const outputMap = new Map();
|
|
97
|
+
// No input files - return empty map
|
|
98
|
+
if (inputFiles.length === 0) {
|
|
99
|
+
return outputMap;
|
|
100
|
+
}
|
|
101
|
+
// Determine output directory or file
|
|
102
|
+
let outputDir;
|
|
103
|
+
let isExplicitFile = false;
|
|
87
104
|
if (!outputPath) {
|
|
88
|
-
//
|
|
89
|
-
|
|
105
|
+
// No output provided - use current directory
|
|
106
|
+
outputDir = process.cwd();
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
else {
|
|
109
|
+
const resolvedOutput = path.resolve(outputPath);
|
|
110
|
+
const outputExt = path.extname(resolvedOutput).toLowerCase();
|
|
111
|
+
if (outputExt) {
|
|
112
|
+
// Output has extension - it's a file path
|
|
113
|
+
if (inputFiles.length > 1) {
|
|
114
|
+
throw new Error('Cannot specify a file output path for multiple input files. Use a directory instead.');
|
|
115
|
+
}
|
|
116
|
+
// Single file with explicit output file
|
|
117
|
+
isExplicitFile = true;
|
|
118
|
+
outputDir = resolvedOutput;
|
|
97
119
|
}
|
|
98
120
|
else {
|
|
99
|
-
//
|
|
100
|
-
|
|
121
|
+
// No extension - it's a directory path
|
|
122
|
+
outputDir = resolvedOutput;
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
125
|
+
// Case 1: Single file with explicit output file path
|
|
126
|
+
if (isExplicitFile && inputFiles.length === 1) {
|
|
127
|
+
// Create parent directory if needed
|
|
128
|
+
const parentDir = path.dirname(outputDir);
|
|
129
|
+
if (!fs.existsSync(parentDir)) {
|
|
130
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
131
|
+
}
|
|
132
|
+
outputMap.set(inputFiles[0], outputDir);
|
|
133
|
+
return outputMap;
|
|
112
134
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @param outputDir - Directory where output files should be placed
|
|
118
|
-
* @param suffix - Suffix to add to output filenames (e.g., "-resized")
|
|
119
|
-
* @param newExtension - New extension for output files (e.g., ".webp")
|
|
120
|
-
* @param preserveStructure - Whether to preserve directory structure for nested inputs
|
|
121
|
-
*/
|
|
122
|
-
export function resolveOutputPaths(inputFiles, outputDir, options = {}) {
|
|
123
|
-
const { suffix = '', newExtension, preserveStructure = false } = options;
|
|
124
|
-
const outputMap = new Map();
|
|
125
|
-
// Find common base path if preserving structure
|
|
126
|
-
let basePath = '';
|
|
127
|
-
if (preserveStructure && inputFiles.length > 1) {
|
|
128
|
-
basePath = findCommonBasePath(inputFiles);
|
|
135
|
+
// Case 2: Multiple files or directory output
|
|
136
|
+
// Create output directory if it doesn't exist
|
|
137
|
+
if (!fs.existsSync(outputDir)) {
|
|
138
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
129
139
|
}
|
|
140
|
+
// Map each input file to output path
|
|
130
141
|
for (const inputFile of inputFiles) {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
let finalOutputDir = outputDir;
|
|
137
|
-
if (preserveStructure && basePath) {
|
|
138
|
-
const relativePath = path.relative(basePath, inputPath.dir);
|
|
139
|
-
finalOutputDir = path.join(outputDir, relativePath);
|
|
140
|
-
// Create nested directories if needed
|
|
141
|
-
if (!fs.existsSync(finalOutputDir)) {
|
|
142
|
-
fs.mkdirSync(finalOutputDir, { recursive: true });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const outputPath = path.join(finalOutputDir, outputFilename);
|
|
146
|
-
outputMap.set(inputFile, outputPath);
|
|
142
|
+
const inputParsed = path.parse(inputFile);
|
|
143
|
+
const ext = newExtension || inputParsed.ext;
|
|
144
|
+
const outputFilename = `${inputParsed.name}${suffix}${ext}`;
|
|
145
|
+
const outputFilePath = path.join(outputDir, outputFilename);
|
|
146
|
+
outputMap.set(inputFile, outputFilePath);
|
|
147
147
|
}
|
|
148
148
|
return outputMap;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
function findCommonBasePath(files) {
|
|
154
|
-
if (files.length === 0)
|
|
155
|
-
return '';
|
|
156
|
-
if (files.length === 1)
|
|
157
|
-
return path.dirname(files[0]);
|
|
158
|
-
const dirs = files.map(f => path.dirname(f));
|
|
159
|
-
const parts = dirs.map(d => d.split(path.sep));
|
|
160
|
-
const minLength = Math.min(...parts.map(p => p.length));
|
|
161
|
-
const commonParts = [];
|
|
162
|
-
for (let i = 0; i < minLength; i++) {
|
|
163
|
-
const part = parts[0][i];
|
|
164
|
-
if (parts.every(p => p[i] === part)) {
|
|
165
|
-
commonParts.push(part);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return commonParts.join(path.sep) || '/';
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Validate paths and return structured result with errors
|
|
175
|
-
* This is a convenience function that combines all validation steps
|
|
151
|
+
* Validate input and output paths
|
|
152
|
+
* Returns validated input files, output directory, and any errors
|
|
176
153
|
*/
|
|
177
154
|
export function validatePaths(inputPath, outputPath, options = {}) {
|
|
155
|
+
const { allowedExtensions = IMAGE_EXTENSIONS } = options;
|
|
178
156
|
const errors = [];
|
|
179
|
-
// Parse
|
|
180
|
-
const inputFiles = parseInputPaths(inputPath,
|
|
157
|
+
// Parse input files
|
|
158
|
+
const inputFiles = parseInputPaths(inputPath, allowedExtensions);
|
|
181
159
|
if (inputFiles.length === 0) {
|
|
182
|
-
errors.push(`No valid
|
|
183
|
-
|
|
184
|
-
|
|
160
|
+
errors.push(`No valid files found. Supported extensions: ${allowedExtensions.join(', ')}`);
|
|
161
|
+
}
|
|
162
|
+
// Validate output path if provided
|
|
163
|
+
if (outputPath) {
|
|
164
|
+
const resolvedOutput = path.resolve(outputPath);
|
|
165
|
+
const outputExt = path.extname(resolvedOutput).toLowerCase();
|
|
166
|
+
// If output has extension but multiple input files
|
|
167
|
+
if (outputExt && inputFiles.length > 1) {
|
|
168
|
+
errors.push('Cannot specify a file output path for multiple input files. Use a directory instead.');
|
|
185
169
|
}
|
|
186
170
|
}
|
|
187
|
-
// Validate output directory
|
|
188
|
-
const outputDir = validateOutputPath(outputPath);
|
|
189
171
|
return {
|
|
190
172
|
inputFiles,
|
|
191
|
-
|
|
173
|
+
outputPath,
|
|
192
174
|
errors,
|
|
193
175
|
};
|
|
194
176
|
}
|
|
195
177
|
/**
|
|
196
|
-
*
|
|
197
|
-
* Plugins can use these or define their own
|
|
178
|
+
* Get file name from path
|
|
198
179
|
*/
|
|
199
|
-
export
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
AUDIO: ['.mp3', '.wav', '.flac', '.aac', '.ogg', '.m4a', '.wma', '.opus', '.ape', '.alac'],
|
|
203
|
-
DOCUMENT: ['.pdf', '.doc', '.docx', '.txt', '.rtf', '.odt', '.md', '.html', '.xml'],
|
|
204
|
-
THREED: ['.obj', '.fbx', '.gltf', '.glb', '.stl', '.dae', '.3ds', '.blend', '.ply'],
|
|
205
|
-
ANIMATION: ['.gif', '.apng', '.webp', '.mp4'],
|
|
206
|
-
ALL: [], // Empty array means all files are allowed
|
|
207
|
-
};
|
|
180
|
+
export function getFileName(filePath) {
|
|
181
|
+
return path.basename(filePath);
|
|
182
|
+
}
|
|
208
183
|
//# sourceMappingURL=pathValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathValidator.js","sourceRoot":"","sources":["../../src/utils/pathValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"pathValidator.js","sourceRoot":"","sources":["../../src/utils/pathValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;CACR,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,oBAA8B,gBAAgB;IAE9C,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,oCAAoC;IACpC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAEtD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAErC,uBAAuB;QACvB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACjC,SAAS,CAAC,0BAA0B;QACtC,CAAC;QAED,MAAM,KAAK,G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