mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-23 23:10:17 +05:30
Reviewer follow-up on Task 12: the task's own title/brief called for
batch support and no later task in the plan picks it up, so this closes
that gap. Adds a "Single File" / "Batch Folder" mode toggle to the
existing media-operations-dialog.js; batch mode swaps the per-file
input/output fields for an Input Folder + "Include subfolders" +
Output Folder trio while keeping every other parameter (width/height/
quality/angle/startTime/duration/crf/fps/format/fit) applied uniformly
to every matching file. Disabled for audio "Merge", which combines many
inputs into one output and doesn't fit a per-file batch model.
main.js: adds collectFilesByExtension() (src/main/collectFilesByExtension.js,
unit tested), a generalization of the inline collectFiles() closure inside
ipcMain.on('universal-convert-batch', ...) to match a set of extensions
instead of one format. runMediaBatchOperation() loops
ImageOperations/AudioOperations/VideoOperations.executeOperation() over
the matched files, reporting per-file progress via new
'media-batch-progress' events and a final 'media-batch-complete' event,
then shows a "Batch Conversion Complete" dialog.showMessageBox with
completed/failed counts, mirroring performBatchConversion()'s pattern.
Wired via three new ipcMain.on handlers: batch-image-operation,
batch-audio-operation, batch-video-operation.
preload.js: whitelists the three new send channels and the two new
receive channels (media-batch-progress, media-batch-complete).
61 lines
2.4 KiB
JavaScript
61 lines
2.4 KiB
JavaScript
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const { collectFilesByExtension } = require('../../src/main/collectFilesByExtension');
|
|
|
|
describe('collectFilesByExtension', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'collectext_'));
|
|
fs.writeFileSync(path.join(tmpDir, 'a.jpg'), 'x');
|
|
fs.writeFileSync(path.join(tmpDir, 'b.PNG'), 'x'); // uppercase extension
|
|
fs.writeFileSync(path.join(tmpDir, 'c.txt'), 'x');
|
|
fs.mkdirSync(path.join(tmpDir, 'sub'));
|
|
fs.writeFileSync(path.join(tmpDir, 'sub', 'd.jpeg'), 'x');
|
|
fs.mkdirSync(path.join(tmpDir, 'sub', 'nested'));
|
|
fs.writeFileSync(path.join(tmpDir, 'sub', 'nested', 'e.jpg'), 'x');
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('matches only files with a listed extension at the top level when includeSubfolders is false', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.jpg', '.png'], false);
|
|
const names = results.map((p) => path.basename(p)).sort();
|
|
expect(names).toEqual(['a.jpg', 'b.PNG']);
|
|
});
|
|
|
|
test('matches extensions case-insensitively', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.png'], false);
|
|
expect(results.map((p) => path.basename(p))).toEqual(['b.PNG']);
|
|
});
|
|
|
|
test('recurses into subfolders when includeSubfolders is true (default)', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.jpg', '.jpeg']);
|
|
const names = results.map((p) => path.basename(p)).sort();
|
|
expect(names).toEqual(['a.jpg', 'd.jpeg', 'e.jpg']);
|
|
});
|
|
|
|
test('does not recurse when includeSubfolders is false', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.jpg', '.jpeg'], false);
|
|
expect(results.map((p) => path.basename(p))).toEqual(['a.jpg']);
|
|
});
|
|
|
|
test('excludes non-matching extensions', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.jpg']);
|
|
expect(results.some((p) => p.endsWith('.txt'))).toBe(false);
|
|
});
|
|
|
|
test('returns an empty array when nothing matches', () => {
|
|
const results = collectFilesByExtension(tmpDir, ['.mp4']);
|
|
expect(results).toEqual([]);
|
|
});
|
|
|
|
test('defaults extensions to an empty list gracefully when omitted', () => {
|
|
expect(() => collectFilesByExtension(tmpDir, undefined, false)).not.toThrow();
|
|
expect(collectFilesByExtension(tmpDir, undefined, false)).toEqual([]);
|
|
});
|
|
});
|