mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-21 15:09:32 +02:00
Renaming service function to mergeVideos
This commit is contained in:
@@ -6,7 +6,7 @@ import ToolFileResult from '@components/result/ToolFileResult';
|
|||||||
import ToolMultipleVideoInput, {
|
import ToolMultipleVideoInput, {
|
||||||
MultiVideoInput
|
MultiVideoInput
|
||||||
} from '@components/input/ToolMultipleVideoInput';
|
} from '@components/input/ToolMultipleVideoInput';
|
||||||
import { main } from './service';
|
import { mergeVideos } from './service';
|
||||||
import { InitialValuesType } from './types';
|
import { InitialValuesType } from './types';
|
||||||
|
|
||||||
const initialValues: InitialValuesType = {};
|
const initialValues: InitialValuesType = {};
|
||||||
@@ -37,7 +37,7 @@ export default function MergeVideo({
|
|||||||
'Files to merge:',
|
'Files to merge:',
|
||||||
files.map((f) => f.name)
|
files.map((f) => f.name)
|
||||||
);
|
);
|
||||||
const mergedBlob = await main(files, initialValues);
|
const mergedBlob = await mergeVideos(files, initialValues);
|
||||||
const mergedFile = new File([mergedBlob], 'merged-video.mp4', {
|
const mergedFile = new File([mergedBlob], 'merged-video.mp4', {
|
||||||
type: 'video/mp4'
|
type: 'video/mp4'
|
||||||
});
|
});
|
||||||
|
@@ -17,7 +17,7 @@ vi.mock('@ffmpeg/util', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Import after mocking
|
// Import after mocking
|
||||||
import { main } from './service';
|
import { mergeVideos } from './service';
|
||||||
|
|
||||||
function createMockFile(name: string, type = 'video/mp4') {
|
function createMockFile(name: string, type = 'video/mp4') {
|
||||||
return new File([new Uint8Array([0, 1, 2])], name, { type });
|
return new File([new Uint8Array([0, 1, 2])], name, { type });
|
||||||
@@ -25,17 +25,17 @@ function createMockFile(name: string, type = 'video/mp4') {
|
|||||||
|
|
||||||
describe('merge-video', () => {
|
describe('merge-video', () => {
|
||||||
it('throws if less than two files are provided', async () => {
|
it('throws if less than two files are provided', async () => {
|
||||||
await expect(main([], {})).rejects.toThrow(
|
await expect(mergeVideos([], {})).rejects.toThrow(
|
||||||
'Please provide at least two video files to merge.'
|
'Please provide at least two video files to merge.'
|
||||||
);
|
);
|
||||||
await expect(main([createMockFile('a.mp4')], {})).rejects.toThrow(
|
await expect(mergeVideos([createMockFile('a.mp4')], {})).rejects.toThrow(
|
||||||
'Please provide at least two video files to merge.'
|
'Please provide at least two video files to merge.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws if input is not an array', async () => {
|
it('throws if input is not an array', async () => {
|
||||||
// @ts-ignore - testing invalid input
|
// @ts-ignore - testing invalid input
|
||||||
await expect(main(null, {})).rejects.toThrow(
|
await expect(mergeVideos(null, {})).rejects.toThrow(
|
||||||
'Please provide at least two video files to merge.'
|
'Please provide at least two video files to merge.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -44,7 +44,7 @@ describe('merge-video', () => {
|
|||||||
const mockFile1 = createMockFile('video1.mp4');
|
const mockFile1 = createMockFile('video1.mp4');
|
||||||
const mockFile2 = createMockFile('video2.mp4');
|
const mockFile2 = createMockFile('video2.mp4');
|
||||||
|
|
||||||
const result = await main([mockFile1, mockFile2], {});
|
const result = await mergeVideos([mockFile1, mockFile2], {});
|
||||||
|
|
||||||
expect(result).toBeInstanceOf(Blob);
|
expect(result).toBeInstanceOf(Blob);
|
||||||
expect(result.type).toBe('video/mp4');
|
expect(result.type).toBe('video/mp4');
|
||||||
|
@@ -4,7 +4,7 @@ import { fetchFile } from '@ffmpeg/util';
|
|||||||
|
|
||||||
// This function will use ffmpeg.wasm to merge multiple video files in the browser.
|
// This function will use ffmpeg.wasm to merge multiple video files in the browser.
|
||||||
// Returns a Promise that resolves to a Blob of the merged video.
|
// Returns a Promise that resolves to a Blob of the merged video.
|
||||||
export async function main(
|
export async function mergeVideos(
|
||||||
input: MergeVideoInput,
|
input: MergeVideoInput,
|
||||||
options: InitialValuesType
|
options: InitialValuesType
|
||||||
): Promise<MergeVideoOutput> {
|
): Promise<MergeVideoOutput> {
|
||||||
|
Reference in New Issue
Block a user