forked from immich-app/immich
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasset-utils.ts
More file actions
48 lines (41 loc) · 1.17 KB
/
asset-utils.ts
File metadata and controls
48 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { AssetEntity } from '@app/infra/db/entities';
import { AssetResponseDto } from '@app/domain';
import fs from 'fs';
const deleteFiles = (asset: AssetEntity | AssetResponseDto) => {
fs.unlink(asset.originalPath, (err) => {
if (err) {
console.log('error deleting ', asset.originalPath);
}
});
// TODO: what if there is no asset.resizePath. Should fail the Job?
// => panoti report: Job not fail
if (asset.resizePath) {
fs.unlink(asset.resizePath, (err) => {
if (err) {
console.log('error deleting ', asset.resizePath);
}
});
}
if (asset.webpPath) {
fs.unlink(asset.webpPath, (err) => {
if (err) {
console.log('error deleting ', asset.webpPath);
}
});
}
if (asset.encodedVideoPath) {
fs.unlink(asset.encodedVideoPath, (err) => {
if (err) {
console.log('error deleting ', asset.encodedVideoPath);
}
});
}
};
const isWebPlayable = (mimeType: string | null): boolean => {
const WEB_PLAYABLE = ['video/webm', 'video/mp4'];
if (mimeType !== null) {
return WEB_PLAYABLE.includes(mimeType);
}
return false;
};
export const assetUtils = { deleteFiles, isWebPlayable };