Files
image-platform/apps/backend/src/presets/presets.controller.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Controller, Get } from "@nestjs/common"
import { ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger"
import {
CUSTOM_TRANSFORM_CONFIG,
IMAGE_PRESETS,
loadAllowedSourceHostsFromEnv,
parseBooleanFlag,
type ImagePreset,
} from "@image-platform/image-config"
import { PresetsResponseDto } from "./presets.dto"
@ApiTags("presets")
@Controller("presets")
export class PresetsController {
@Get()
@ApiOperation({
summary: "получить доступные presets и custom config",
description: "Возвращает статический config presets, custom transform limits и mock allowlist source hosts.",
})
@ApiOkResponse({ description: "Конфигурация presets возвращена.", type: PresetsResponseDto })
getPresets(): PresetsResponseDto {
return {
allowedSourceHosts: [...loadAllowedSourceHostsFromEnv()],
custom: {
enabled: parseBooleanFlag(process.env.IMAGE_ALLOW_CUSTOM_TRANSFORMS, false),
formats: CUSTOM_TRANSFORM_CONFIG.formats,
maxHeight: CUSTOM_TRANSFORM_CONFIG.maxHeight,
maxWidth: CUSTOM_TRANSFORM_CONFIG.maxWidth,
quality: CUSTOM_TRANSFORM_CONFIG.quality,
},
presets: Object.entries(IMAGE_PRESETS).map(([name, preset]) => {
const config: ImagePreset = preset
return {
formats: config.formats,
height: config.height,
mode: config.mode,
name,
qualities: config.qualities,
quality: config.quality,
resize: config.resize,
width: config.width,
widths: config.widths,
}
}),
}
}
}