Picsur/shared/src/util/parse-mime.ts
2022-04-16 16:35:28 +02:00

13 lines
468 B
TypeScript

import { FullMime, SupportedAnimMimes, SupportedImageMimes, SupportedMimeCategory } from '../dto/mimes.dto';
import { Fail, Failable } from '../types';
export function ParseMime(mime: string): Failable<FullMime> {
if (SupportedImageMimes.includes(mime)) {
return { mime, type: SupportedMimeCategory.Image };
}
if (SupportedAnimMimes.includes(mime)) {
return { mime, type: SupportedMimeCategory.Animation };
}
return Fail('Unsupported mime type');
}