ngx-dsxlibrary 2.21.11 → 2.21.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4494,6 +4494,8 @@ class UtilityAddService {
|
|
|
4494
4494
|
*
|
|
4495
4495
|
* @param blob Objeto Blob del archivo a descargar
|
|
4496
4496
|
* @param fileName Nombre completo del archivo incluyendo extensión
|
|
4497
|
+
* @param expectedExtension Extensión esperada (opcional). Si se envía y no coincide
|
|
4498
|
+
* con la extensión final del archivo, se abrirá en una nueva pestaña en lugar de descargar.
|
|
4497
4499
|
*
|
|
4498
4500
|
* @example
|
|
4499
4501
|
* // Opción 1: Usar directamente con un blob
|
|
@@ -4505,16 +4507,33 @@ class UtilityAddService {
|
|
|
4505
4507
|
* this.utilityAddService.descargarBlob(blob, fileName);
|
|
4506
4508
|
* });
|
|
4507
4509
|
*/
|
|
4508
|
-
descargarBlob(blob, fileName) {
|
|
4510
|
+
descargarBlob(blob, fileName, expectedExtension) {
|
|
4509
4511
|
if (!blob) {
|
|
4510
4512
|
console.warn('No se proporcionó un blob válido para descargar.');
|
|
4511
4513
|
return;
|
|
4512
4514
|
}
|
|
4513
4515
|
const fileUrl = URL.createObjectURL(blob);
|
|
4514
|
-
const downloadLink = document.createElement('a');
|
|
4515
|
-
downloadLink.href = fileUrl;
|
|
4516
4516
|
const baseFileName = fileName?.trim() || 'archivo_descargado';
|
|
4517
4517
|
const fullFileName = this.ensureFileNameWithExtension(baseFileName, blob.type);
|
|
4518
|
+
const normalizedExpectedExtension = (expectedExtension || '')
|
|
4519
|
+
.trim()
|
|
4520
|
+
.toLowerCase();
|
|
4521
|
+
if (normalizedExpectedExtension) {
|
|
4522
|
+
const expectedWithDot = normalizedExpectedExtension.startsWith('.')
|
|
4523
|
+
? normalizedExpectedExtension
|
|
4524
|
+
: `.${normalizedExpectedExtension}`;
|
|
4525
|
+
const currentExtensionMatch = /\.[^./\\]+$/.exec(fullFileName);
|
|
4526
|
+
const currentExtension = currentExtensionMatch
|
|
4527
|
+
? currentExtensionMatch[0].toLowerCase()
|
|
4528
|
+
: '';
|
|
4529
|
+
if (currentExtension !== expectedWithDot) {
|
|
4530
|
+
window.open(fileUrl, '_blank');
|
|
4531
|
+
this.revokeObjectUrl(fileUrl);
|
|
4532
|
+
return;
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
const downloadLink = document.createElement('a');
|
|
4536
|
+
downloadLink.href = fileUrl;
|
|
4518
4537
|
downloadLink.download = fullFileName;
|
|
4519
4538
|
downloadLink.click();
|
|
4520
4539
|
this.revokeObjectUrl(fileUrl);
|