mirror of
https://github.com/CaramelFur/Picsur.git
synced 2026-07-01 00:18:13 +02:00
make extension optional for image request
This commit is contained in:
@@ -12,18 +12,26 @@ import { ImageFullId } from '../../models/constants/image-full-id.const';
|
||||
export class ImageFullIdPipe implements PipeTransform<string, ImageFullId> {
|
||||
transform(value: string, metadata: ArgumentMetadata): ImageFullId {
|
||||
const split = value.split('.');
|
||||
if (split.length !== 2)
|
||||
if (split.length === 2) {
|
||||
const [id, ext] = split;
|
||||
if (!UUIDRegex.test(id))
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
const mime = Ext2Mime(ext);
|
||||
|
||||
if (mime === undefined)
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
return { id, ext, mime };
|
||||
} else if (split.length === 1) {
|
||||
const [id] = split;
|
||||
|
||||
if (!UUIDRegex.test(id))
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
return { id, ext: null, mime: null };
|
||||
} else {
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
const [id, ext] = split;
|
||||
if (!UUIDRegex.test(id))
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
const mime = Ext2Mime(ext);
|
||||
|
||||
if (mime === undefined)
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
return { id, ext, mime };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
export interface ImageFullId {
|
||||
interface NormalImage {
|
||||
id: string;
|
||||
ext: string;
|
||||
mime: string;
|
||||
}
|
||||
|
||||
interface OriginalImage {
|
||||
id: string;
|
||||
ext: null;
|
||||
mime: null;
|
||||
}
|
||||
|
||||
export type ImageFullId = NormalImage | OriginalImage;
|
||||
|
||||
Reference in New Issue
Block a user