mirror of
https://github.com/immich-app/immich.git
synced 2026-06-12 19:11:52 -07:00
actually validate
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Controller, Delete, Get, Header, Headers, HttpCode, HttpStatus, Next, Param, Res } from '@nestjs/common';
|
||||
import { ApiProduces, ApiTags } from '@nestjs/swagger';
|
||||
import { NextFunction, Response } from 'express';
|
||||
import { ZodValidationException } from 'nestjs-zod';
|
||||
import { HLS_PLAYLIST_CONTENT_TYPE } from 'src/constants';
|
||||
import { Endpoint, HistoryBuilder } from 'src/decorators';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
@@ -64,14 +65,19 @@ export class VideoStreamController {
|
||||
async getSegment(
|
||||
@Auth() auth: AuthDto,
|
||||
@Param() { id, sessionId, variantIndex, filename }: HlsSegmentParamDto,
|
||||
@Headers() { [ImmichHeader.HlsTargetSegment]: targetSegment }: HlsSegmentHeaderDto,
|
||||
@Headers() headers: HlsSegmentHeaderDto,
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
) {
|
||||
try {
|
||||
headers = HlsSegmentHeaderDto.create(headers);
|
||||
} catch (err) {
|
||||
throw new ZodValidationException(err);
|
||||
}
|
||||
await sendFile(
|
||||
res,
|
||||
next,
|
||||
() => this.service.getSegment(auth, id, sessionId, variantIndex, filename, targetSegment),
|
||||
() => this.service.getSegment(auth, id, sessionId, variantIndex, filename, headers[ImmichHeader.HlsInitSegment]),
|
||||
this.logger,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class HlsSegmentParamDto extends createZodDto(HlsSegmentParamSchema) {}
|
||||
|
||||
const HlsSegmentHeaderSchema = z.object({
|
||||
// Lets the client hint at which segment will be loaded after init.mp4.
|
||||
[ImmichHeader.HlsTargetSegment]: z.coerce.number().int().min(0).optional(),
|
||||
[ImmichHeader.HlsInitSegment]: z.coerce.number().int().min(0).optional(),
|
||||
});
|
||||
|
||||
export class HlsSegmentHeaderDto extends createZodDto(HlsSegmentHeaderSchema) {}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ export enum ImmichHeader {
|
||||
SharedLinkSlug = 'x-immich-share-slug',
|
||||
Checksum = 'x-immich-checksum',
|
||||
CorrelationId = 'X-Correlation-ID',
|
||||
HlsTargetSegment = 'x-immich-hls-msn',
|
||||
HlsInitSegment = 'x-immich-hls-msn',
|
||||
}
|
||||
|
||||
export enum ImmichQuery {
|
||||
|
||||
Reference in New Issue
Block a user