ability to send original image if wanted
This commit is contained in:
parent
e9dc11ab70
commit
4c3a00f661
|
@ -22,14 +22,14 @@ export class ImageFullIdPipe implements PipeTransform<string, ImageFullId> {
|
|||
if (mime === undefined)
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
|
||||
return { id, ext, mime };
|
||||
return { type: 'normal', 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 };
|
||||
return { type: 'original', id, ext: null, mime: null };
|
||||
} else {
|
||||
throw new BadRequestException('Invalid image identifier');
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
interface NormalImage {
|
||||
type: 'normal';
|
||||
id: string;
|
||||
ext: string;
|
||||
mime: string;
|
||||
}
|
||||
|
||||
interface OriginalImage {
|
||||
type: 'original';
|
||||
id: string;
|
||||
ext: null;
|
||||
mime: null;
|
||||
|
|
|
@ -5,8 +5,7 @@ import {
|
|||
InternalServerErrorException,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
Post,
|
||||
Res
|
||||
Post, Res
|
||||
} from '@nestjs/common';
|
||||
import { FastifyReply } from 'fastify';
|
||||
import { ImageMetaResponse } from 'picsur-shared/dist/dto/api/image.dto';
|
||||
|
@ -37,6 +36,17 @@ export class ImageController {
|
|||
@Res({ passthrough: true }) res: FastifyReply,
|
||||
@ImageFullIdParam() fullid: ImageFullId,
|
||||
): Promise<Buffer> {
|
||||
if (fullid.type === 'original') {
|
||||
const image = await this.imagesService.getOriginal(fullid.id);
|
||||
if (HasFailed(image)) {
|
||||
this.logger.warn(image.getReason());
|
||||
throw new NotFoundException('Could not find image');
|
||||
}
|
||||
|
||||
res.type(image.mime);
|
||||
return image.data;
|
||||
}
|
||||
|
||||
const image = await this.imagesService.getMaster(fullid.id);
|
||||
if (HasFailed(image)) {
|
||||
this.logger.warn(image.getReason());
|
||||
|
@ -52,13 +62,18 @@ export class ImageController {
|
|||
@Res({ passthrough: true }) res: FastifyReply,
|
||||
@ImageFullIdParam() fullid: ImageFullId,
|
||||
) {
|
||||
const fullmime = await this.imagesService.getMasterMime(fullid.id);
|
||||
if (HasFailed(fullmime)) {
|
||||
this.logger.warn(fullmime.getReason());
|
||||
throw new NotFoundException('Could not find image');
|
||||
if (fullid.type === 'original') {
|
||||
const fullmime = await this.imagesService.getOriginalMime(fullid.id);
|
||||
if (HasFailed(fullmime)) {
|
||||
this.logger.warn(fullmime.getReason());
|
||||
throw new NotFoundException('Could not find image');
|
||||
}
|
||||
|
||||
res.type(fullmime.mime);
|
||||
return;
|
||||
}
|
||||
|
||||
res.type(fullmime.mime);
|
||||
res.type(fullid.mime);
|
||||
}
|
||||
|
||||
@Get('meta/:id')
|
||||
|
|
Loading…
Reference in a new issue