the banner edit is ready and name of participant its getting update in eache event
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
@@ -26,13 +27,40 @@ export class CarouselController {
|
||||
storage: diskStorage({
|
||||
destination: './public',
|
||||
filename: function (req, file, cb) {
|
||||
cb(null, file.originalname);
|
||||
const directory = './public';
|
||||
const filePath = `${directory}/${file.originalname}`;
|
||||
if (fs.existsSync(filePath)) {
|
||||
cb(
|
||||
new BadRequestException(
|
||||
`Ya existe un archivo con el nombre: '${file.originalname}'. Si está seguro de que no es el mismo, cambie el nombre del archivo.`,
|
||||
),
|
||||
null,
|
||||
);
|
||||
} else {
|
||||
cb(null, file.originalname);
|
||||
}
|
||||
},
|
||||
}),
|
||||
fileFilter: function (req, file, cb) {
|
||||
const filetypes = /jpeg|jpg|webp|png/;
|
||||
const extname = filetypes.test(
|
||||
path.extname(file.originalname).toLowerCase(),
|
||||
);
|
||||
const mimetype = filetypes.test(file.mimetype);
|
||||
if (mimetype && extname) {
|
||||
return cb(null, true);
|
||||
}
|
||||
cb(
|
||||
new BadRequestException(
|
||||
'Lo sentimos, para mejorar la calidad de las imagenes en el carousel solo se aceptan imagenes con terminación: .jpeg .jpg .png .webp',
|
||||
),
|
||||
false,
|
||||
);
|
||||
},
|
||||
}),
|
||||
)
|
||||
async addImage(@UploadedFile() file) {
|
||||
return {msg: 'Imagen guardada con exito :)'}
|
||||
return { msg: 'Imagen guardada con exito :)' };
|
||||
}
|
||||
|
||||
@Delete('/imagenes/:nombreArchivo')
|
||||
@@ -48,12 +76,16 @@ export class CarouselController {
|
||||
@Get('/imagenes')
|
||||
async getImages(@Res() res: Response) {
|
||||
// Leer el directorio 'public' para obtener el nombre de todos los archivos
|
||||
|
||||
const fileNames = await fs.promises.readdir('./public');
|
||||
// Generar la URL para cada archivo y agregarla a un arreglo
|
||||
const baseUrl = 'http://localhost:5089'; // reemplaza con la URL de tu servidor
|
||||
const imageUrls = fileNames.map(
|
||||
(fileName) => `${baseUrl}/public/${fileName}`,
|
||||
|
||||
// Filtrar solo las imágenes con las terminaciones "jpg", "webp" y "png"
|
||||
const imageNames = fileNames.filter((fileName) =>
|
||||
['.jpg', '.webp', '.png'].includes(path.extname(fileName)),
|
||||
);
|
||||
|
||||
const imageUrls = imageNames.map((imageName) => `public/${imageName}`);
|
||||
// Devolver el arreglo de URLs como respuesta
|
||||
return res.json(imageUrls);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user