website refactor
This commit is contained in:
@@ -19,9 +19,7 @@ import type { MulterFile } from './types/MulterFile';
|
||||
import { MediaGenerationService } from '@core/media/domain/services/MediaGenerationService';
|
||||
import type { Logger } from '@core/shared/application/Logger';
|
||||
import { MediaReference } from '@core/domain/media/MediaReference';
|
||||
import { MediaResolverAdapter } from '@adapters/media/MediaResolverAdapter';
|
||||
import { LOGGER_TOKEN, MEDIA_STORAGE_PORT_TOKEN } from './MediaTokens';
|
||||
import type { MediaStoragePort } from '@core/media/application/ports/MediaStoragePort';
|
||||
import { LOGGER_TOKEN } from './MediaTokens';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
@@ -36,8 +34,6 @@ export class MediaController {
|
||||
@Inject(MediaService) private readonly mediaService: MediaService,
|
||||
@Inject(MediaGenerationService) private readonly mediaGenerationService: MediaGenerationService,
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
@Inject(MediaResolverAdapter) private readonly mediaResolver: MediaResolverAdapter,
|
||||
@Inject(MEDIA_STORAGE_PORT_TOKEN) private readonly mediaStorage: MediaStoragePort,
|
||||
) {}
|
||||
|
||||
@Post('avatar/generate')
|
||||
@@ -272,23 +268,19 @@ export class MediaController {
|
||||
// The mediaId is used as the storage key
|
||||
const storageKey = `uploaded/${mediaId}`;
|
||||
|
||||
// Get file bytes from storage
|
||||
const bytes = await this.mediaStorage.getBytes!(storageKey);
|
||||
if (!bytes) {
|
||||
// Get file bytes from storage via service
|
||||
const result = await this.mediaService.getUploadedMedia(storageKey);
|
||||
if (!result) {
|
||||
this.logger.warn('[MediaController] Uploaded media file not found', { mediaId, storageKey });
|
||||
res.status(HttpStatus.NOT_FOUND).json({ error: 'Media file not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Get metadata to determine content type
|
||||
const metadata = await this.mediaStorage.getMetadata!(storageKey);
|
||||
const contentType = metadata?.contentType || 'application/octet-stream';
|
||||
|
||||
res.setHeader('Content-Type', contentType);
|
||||
res.setHeader('Content-Type', result.contentType);
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
res.status(HttpStatus.OK).send(bytes);
|
||||
res.status(HttpStatus.OK).send(result.bytes);
|
||||
|
||||
this.logger.info('[MediaController] Uploaded media served', { mediaId, storageKey, size: bytes.length });
|
||||
this.logger.info('[MediaController] Uploaded media served', { mediaId, storageKey, size: result.bytes.length });
|
||||
}
|
||||
|
||||
@Public()
|
||||
@@ -339,7 +331,7 @@ export class MediaController {
|
||||
|
||||
if (ref) {
|
||||
refHash = ref.hash();
|
||||
resolvedPath = await this.mediaResolver.resolve(ref);
|
||||
resolvedPath = await this.mediaService.resolveMediaReference(ref);
|
||||
|
||||
if (!resolvedPath) {
|
||||
notes.push('Resolver returned null');
|
||||
@@ -382,7 +374,7 @@ export class MediaController {
|
||||
): Promise<void> {
|
||||
this.logger.debug('[MediaController] Getting media details', { mediaId });
|
||||
const dto: GetMediaOutputDTO | null = await this.mediaService.getMedia(mediaId);
|
||||
|
||||
|
||||
if (dto) {
|
||||
this.logger.info('[MediaController] Media details found', { mediaId });
|
||||
res.status(HttpStatus.OK).json(dto);
|
||||
|
||||
Reference in New Issue
Block a user