mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix: asset upload metadata validation (#21594)
This commit is contained in:
parent
7bd79b551c
commit
6e7c2817a3
3 changed files with 106 additions and 24 deletions
|
|
@ -1,12 +1,16 @@
|
|||
import { CallHandler, Provider, ValidationPipe } from '@nestjs/common';
|
||||
import { CallHandler, ExecutionContext, Provider, ValidationPipe } from '@nestjs/common';
|
||||
import { APP_GUARD, APP_PIPE } from '@nestjs/core';
|
||||
import { transformException } from '@nestjs/platform-express/multer/multer/multer.utils';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { ClassConstructor } from 'class-transformer';
|
||||
import { NextFunction } from 'express';
|
||||
import { Kysely } from 'kysely';
|
||||
import multer from 'multer';
|
||||
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
||||
import { Readable, Writable } from 'node:stream';
|
||||
import { PNG } from 'pngjs';
|
||||
import postgres from 'postgres';
|
||||
import { UploadFieldName } from 'src/dtos/asset-media.dto';
|
||||
import { AssetUploadInterceptor } from 'src/middleware/asset-upload.interceptor';
|
||||
import { AuthGuard } from 'src/middleware/auth.guard';
|
||||
import { FileUploadInterceptor } from 'src/middleware/file-upload.interceptor';
|
||||
|
|
@ -82,6 +86,24 @@ export type ControllerContext = {
|
|||
|
||||
export const controllerSetup = async (controller: ClassConstructor<unknown>, providers: Provider[]) => {
|
||||
const noopInterceptor = { intercept: (ctx: never, next: CallHandler<unknown>) => next.handle() };
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
const memoryFileInterceptor = {
|
||||
intercept: async (ctx: ExecutionContext, next: CallHandler<unknown>) => {
|
||||
const context = ctx.switchToHttp();
|
||||
const handler = upload.fields([
|
||||
{ name: UploadFieldName.ASSET_DATA, maxCount: 1 },
|
||||
{ name: UploadFieldName.SIDECAR_DATA, maxCount: 1 },
|
||||
]);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const next: NextFunction = (error) => (error ? reject(transformException(error)) : resolve());
|
||||
const maybePromise = handler(context.getRequest(), context.getResponse(), next);
|
||||
Promise.resolve(maybePromise).catch((error) => reject(error));
|
||||
});
|
||||
|
||||
return next.handle();
|
||||
},
|
||||
};
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
controllers: [controller],
|
||||
providers: [
|
||||
|
|
@ -93,7 +115,7 @@ export const controllerSetup = async (controller: ClassConstructor<unknown>, pro
|
|||
],
|
||||
})
|
||||
.overrideInterceptor(FileUploadInterceptor)
|
||||
.useValue(noopInterceptor)
|
||||
.useValue(memoryFileInterceptor)
|
||||
.overrideInterceptor(AssetUploadInterceptor)
|
||||
.useValue(noopInterceptor)
|
||||
.compile();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue