Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed execution with exec of ffmpeg and ffprobe #2

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = {
],
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/strict-boolean-expressions": "off",
}
}
42 changes: 41 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@types/fluent-ffmpeg": "^2.1.21",
"@types/node": "^20.4.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"eslint": "^8.44.0",
Expand All @@ -40,5 +41,8 @@
"nodemon": "^3.0.1",
"prettier": "^3.0.0",
"typescript": "^5.1.6"
},
"dependencies": {
"fluent-ffmpeg": "^2.1.2"
}
}
70 changes: 55 additions & 15 deletions packages/shared/src/domain/value-objects/file-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
assert.strictEqual(fileInfo.name, 'video.mp4', 'should have the same name');
assert.strictEqual(fileInfo.size, 100000, 'should have the same size');
Expand All @@ -24,21 +25,28 @@ describe('FileInfo', () => {
'should have the same extension'
);
assert.strictEqual(fileInfo.path, 'path', 'should have the same path');
assert.strictEqual(
fileInfo.folder,
'/folder',
'should have the same folder'
);
});
it('should compare equally file infos with same name, size, mime type, extension and path', () => {
const fileInfo = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
assert(fileInfo.equals(fileInfo2), 'should be equal');
});
Expand All @@ -48,14 +56,16 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video2.mp4',
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder2'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand All @@ -65,14 +75,16 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video2.mp4',
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand All @@ -82,14 +94,16 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
200000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand All @@ -99,14 +113,16 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
100000,
'video/mp3',
'mp4',
'path'
'path',
'/folder'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand All @@ -116,14 +132,16 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp3',
'path'
'path',
'/folder'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand All @@ -133,14 +151,36 @@ describe('FileInfo', () => {
100000,
'video/mp4',
'mp4',
'path'
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp4',
'path2',
'/folder'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});

it('should compare different file infos with different folder', () => {
const fileInfo = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp4',
'path',
'/folder'
);
const fileInfo2 = new FileInfo(
'video.mp4',
100000,
'video/mp4',
'mp4',
'path2'
'path',
'/folder2'
);
assert(!fileInfo.equals(fileInfo2), 'should not be equal');
});
Expand Down
12 changes: 10 additions & 2 deletions packages/shared/src/domain/value-objects/file-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ export default class FileInfo {
private readonly _mimeType: string;
private readonly _extension: string;
private readonly _path: string;
private readonly _folder: string;

constructor(
name: string,
size: number,
mimeType: string,
extension: string,
path: string
path: string,
folder: string
) {
this._name = name;
this._size = size;
this._mimeType = mimeType;
this._extension = extension;
this._path = path;
this._folder = folder;
}

public get name(): string {
Expand All @@ -39,13 +42,18 @@ export default class FileInfo {
return this._path;
}

public get folder(): string {
return this._folder;
}

public equals(other: FileInfo): boolean {
return (
this.name === other.name &&
this.size === other.size &&
this.mimeType === other.mimeType &&
this.extension === other.extension &&
this.path === other.path
this.path === other.path &&
this.folder === other.folder
);
}
}
6 changes: 6 additions & 0 deletions packages/shared/src/errors/devflix-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class DevFlixError extends Error {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = this.constructor.name;
}
}
8 changes: 8 additions & 0 deletions packages/shared/src/errors/ffmpeg-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DevFlixError from './devflix-error.js';

export default class FFMPEGError extends DevFlixError {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = this.constructor.name;
}
}
3 changes: 1 addition & 2 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Entity from './domain/entity/entity.js';
import UlidUniqueID from './domain/value-objects/ulid-unique-id.js';
import ffmpeg from './utils/ffmpeg.js';
import ffprobe from './utils/ffprobe.js';
import FileInfo from './domain/value-objects/file-info.js';
import Resolution from './domain/value-objects/resolution.js';
import RootDir from './utils/root-dir.js';

export { Entity, UlidUniqueID, ffmpeg, FileInfo, Resolution, ffprobe, RootDir };
export { Entity, UlidUniqueID, ffmpeg, FileInfo, Resolution, RootDir };
Loading