Files
immich/server/libs/common/src/utils/asset-utils.ts
Skyler Mäntysaari 8eb82836b9 feat(server): Support webm videos (#1365)
* feat(server): Support webm without transcoding.

Transcoding result doesn't appear to be used by anything expect for quicktime.

* feat(server): Fix the asset uploader for .avi

It needs to be transcoded.

* feat(server): Most browsers doesn't support avi so use mp4.

* feat(server): Address PR comments

* Addressed the PR comments

I moved the function that checks the mimetype to a central location in asset-utils and made tests for it.

* Rollbacked to the way transcoder was decising things to transcode.
2023-01-21 15:52:40 -06:00

49 lines
1.2 KiB
TypeScript

import { AssetEntity } from '@app/infra';
import { AssetResponseDto } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto';
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 };