fixed images
This commit is contained in:
+9
-4
@@ -1,5 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
import { join } from 'path';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
@@ -15,10 +17,9 @@ import { ProyectosAcademicos } from './proyectos_academicos/entities/proyectos_a
|
||||
import { TipoUsuario } from './tipo_usuario/entities/tipo_usuario.entity';
|
||||
import { ProfesorModule } from './Profesor/profesor.module';
|
||||
import { Profesor } from './Profesor/entities/profesor.entity';
|
||||
|
||||
import { AdscripcionModule } from "./adscripcion/adscripcion.module";
|
||||
import { EdificioModule } from "./edificio/edificio.module";
|
||||
import { CategoriaModule } from "./categoria/categoria.module";
|
||||
import { AdscripcionModule } from './adscripcion/adscripcion.module';
|
||||
import { EdificioModule } from './edificio/edificio.module';
|
||||
import { CategoriaModule } from './categoria/categoria.module';
|
||||
import { DatosAcademicosModule } from './datos_academicos/datos_academicos.module';
|
||||
import { LineasInvestigacionModule } from './lineas_investigacion/lineas_investigacion.module';
|
||||
import { ProyectosAcademicosModule } from './proyectos_academicos/proyectos_academicos.module';
|
||||
@@ -56,6 +57,10 @@ import { ImagenModule } from './images/images.module';
|
||||
synchronize: true,
|
||||
}),
|
||||
}),
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join(__dirname, '..', 'imagenes'),
|
||||
serveRoot: '/imagenes',
|
||||
}),
|
||||
ImagenModule,
|
||||
ProfesorModule,
|
||||
AdscripcionModule,
|
||||
|
||||
@@ -21,17 +21,18 @@ export class ImagenService {
|
||||
const buffer = Buffer.from(fotografia.split(',')[1], 'base64');
|
||||
const sanitizedFileName = nombre.replace(/\s+/g, '_').toLowerCase();
|
||||
const imageName = `${sanitizedFileName}.${ext}`;
|
||||
const imagePath = path.join(__dirname, '..', 'imagenes', imageName);
|
||||
|
||||
// Save image to the 'imagenes' directory in the root of the project
|
||||
const imagePath = path.join(process.cwd(), 'imagenes', imageName);
|
||||
|
||||
// Ensure the directory exists
|
||||
const dirPath = path.join(__dirname, '..', 'imagenes');
|
||||
const dirPath = path.join(process.cwd(), 'imagenes');
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
|
||||
await sharp(buffer)
|
||||
.toFile(imagePath);
|
||||
await sharp(buffer).toFile(imagePath);
|
||||
|
||||
return `/dist/imagenes/${imageName}`;
|
||||
return `/imagenes/${imageName}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user