Picsur/shared/src/util/parse-mime.ts
2022-07-19 14:54:02 +02:00

18 lines
488 B
TypeScript

import {
FullMime,
SupportedAnimMimes,
SupportedImageMimes,
SupportedMimeCategory
} from '../dto/mimes.dto';
import { Fail, Failable, FT } 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(FT.UsrValidation, 'Unsupported mime type');
}