@topconsultnpm/sdkui-react 6.21.0-dev2.50 → 6.21.0-dev2.51
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.
- package/lib/hooks/useDcmtOperations.js +44 -12
- package/package.json +1 -1
|
@@ -18,16 +18,49 @@ const isScannerLicenseConfigured = () => {
|
|
|
18
18
|
};
|
|
19
19
|
let abortController = new AbortController();
|
|
20
20
|
const downloadCountMap = new Map();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Genera il nome file per il download con fallback: backend → fileName → DID.
|
|
23
|
+
* Aggiunge estensione se mancante e gestisce duplicati per file multi-estensione.
|
|
24
|
+
*/
|
|
25
|
+
const getDownloadFileName = (file, dcmtInfo) => {
|
|
26
|
+
// === FASE 1: Costruzione nome base con fallback ===
|
|
27
|
+
// Determina l'estensione con fallback
|
|
28
|
+
const fileExtFromBackend = file?.name?.split('.').pop()?.toLowerCase();
|
|
29
|
+
const fileExtFromDcmt = dcmtInfo.FILEEXT?.toLowerCase();
|
|
30
|
+
const fileExtension = fileExtFromBackend ?? fileExtFromDcmt ?? '';
|
|
31
|
+
let baseFileName;
|
|
32
|
+
// 1. Priorità massima: nome dal backend
|
|
33
|
+
if (file?.name) {
|
|
34
|
+
baseFileName = file.name;
|
|
35
|
+
}
|
|
36
|
+
// 2. Seconda priorità: nome salvato nel documento
|
|
37
|
+
else if (dcmtInfo.fileName) {
|
|
38
|
+
const hasExtension = dcmtInfo.fileName.includes('.');
|
|
39
|
+
baseFileName = hasExtension
|
|
40
|
+
? dcmtInfo.fileName
|
|
41
|
+
: (fileExtension ? `${dcmtInfo.fileName}.${fileExtension}` : dcmtInfo.fileName);
|
|
42
|
+
}
|
|
43
|
+
// 3. Fallback finale: ID documento con estensione
|
|
44
|
+
else {
|
|
45
|
+
baseFileName = fileExtension ? `${dcmtInfo.DID}.${fileExtension}` : `${dcmtInfo.DID}`;
|
|
46
|
+
}
|
|
47
|
+
// === FASE 2: Gestione duplicati per file con estensioni multiple ===
|
|
48
|
+
const firstDot = baseFileName.indexOf('.');
|
|
49
|
+
const lastDot = baseFileName.lastIndexOf('.');
|
|
50
|
+
// Se non ci sono punti o c'è una sola estensione, ritorna il nome così com'è
|
|
51
|
+
if (firstDot === -1 || firstDot === lastDot) {
|
|
52
|
+
return baseFileName;
|
|
53
|
+
}
|
|
54
|
+
// Gestisce il contatore per evitare sovrascritture
|
|
55
|
+
const count = downloadCountMap.get(baseFileName) ?? 0;
|
|
56
|
+
downloadCountMap.set(baseFileName, count + 1);
|
|
57
|
+
// Prima occorrenza: nome originale
|
|
58
|
+
if (count === 0) {
|
|
59
|
+
return baseFileName;
|
|
60
|
+
}
|
|
61
|
+
// Download successivi: inserisce contatore dopo il nome base
|
|
62
|
+
// Es: "file.pdf.p7m" -> "file(1).pdf.p7m"
|
|
63
|
+
return `${baseFileName.slice(0, firstDot)}(${count})${baseFileName.slice(firstDot)}`;
|
|
31
64
|
};
|
|
32
65
|
export const useDcmtOperations = () => {
|
|
33
66
|
const [showWaitPanel, setShowWaitPanel] = useState(false);
|
|
@@ -126,8 +159,7 @@ export const useDcmtOperations = () => {
|
|
|
126
159
|
else {
|
|
127
160
|
const alink2 = document.createElement('a');
|
|
128
161
|
alink2.href = fileURL;
|
|
129
|
-
|
|
130
|
-
alink2.download = getDownloadFileName(baseFileName);
|
|
162
|
+
alink2.download = getDownloadFileName(file, inputDcmts[i]);
|
|
131
163
|
alink2.target = "_blank";
|
|
132
164
|
alink2.rel = "noreferrer";
|
|
133
165
|
alink2.click();
|