Update codegenie download
This commit is contained in:
@@ -94,7 +94,7 @@
|
||||
<ul class="file-list">
|
||||
<li class="file-item">
|
||||
sf_document-{{ execution_id }}
|
||||
<Button icon="pi pi-download" class="p-button-text p-button-sm" label="Download" @click="downloadFile(inputs['SingleFileUpload'])" />
|
||||
<Button icon="pi pi-download" class="p-button-text p-button-sm" label="Download" @click="downloadCodegenieFile(scenario_output)" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -319,50 +319,6 @@ const getFileNamesInput = (zipData) => {
|
||||
return files;
|
||||
};
|
||||
|
||||
// Funzione per scaricare il file
|
||||
const downloadFileInput = async (fileName) => {
|
||||
if (!zipInput.value) return;
|
||||
|
||||
try {
|
||||
// Estrai il file dallo zip
|
||||
const fileContent = await zipInput.value.file(fileName).async('blob');
|
||||
const url = URL.createObjectURL(fileContent);
|
||||
|
||||
// Crea un link per scaricare il file
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error(`Error downloading file "${fileName}":`, error);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadFileOutput = async (fileName) => {
|
||||
if (!zipOutput.value) return;
|
||||
|
||||
try {
|
||||
// Estrai il file dallo zip
|
||||
const fileContent = await zipOutput.value.file(fileName).async('blob');
|
||||
const url = URL.createObjectURL(fileContent);
|
||||
|
||||
// Crea un link per scaricare il file
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error(`Error downloading file "${fileName}":`, error);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadFile = async (filePath) => {
|
||||
try {
|
||||
@@ -389,71 +345,34 @@ const downloadFile = async (filePath) => {
|
||||
}
|
||||
};
|
||||
|
||||
const downloadFolderFromBase64 = async (base64String) => {
|
||||
try {
|
||||
// Decodifica la stringa base64 in un array di byte
|
||||
const binaryString = atob(base64String); // Decodifica base64 in una stringa binaria
|
||||
const byteArray = new Uint8Array(binaryString.length); // Crea un array di byte
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
byteArray[i] = binaryString.charCodeAt(i); // Popola l'array di byte
|
||||
const downloadCodegenieFile = (base64String) => {
|
||||
// Decodifica la stringa Base64
|
||||
const binaryString = atob(base64String);
|
||||
const binaryLength = binaryString.length;
|
||||
const bytes = new Uint8Array(binaryLength);
|
||||
|
||||
for (let i = 0; i < binaryLength; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
|
||||
// Crea un oggetto JSZip per lavorare con il contenuto ZIP
|
||||
const zip = await JSZip.loadAsync(byteArray); // Carica direttamente l'array di byte
|
||||
// Creazione di un Blob dal file binario
|
||||
const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
|
||||
|
||||
// Estrai il primo nome della cartella presente nello ZIP
|
||||
let folderName = Object.keys(zip.files).find((file) => zip.files[file].dir); // Trova il primo file che è una cartella
|
||||
// Creazione di un URL per il Blob
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Se non è stata trovata alcuna cartella, creiamo una cartella chiamata "folderToDownload"
|
||||
if (!folderName) {
|
||||
folderName = 'docOutput-' + execution_id.value;
|
||||
console.log(`No folders founded in the ZIP. Creating a new folder: "${folderName}".`);
|
||||
}
|
||||
// Creazione di un elemento anchor per il download
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = 'sf_document-' + execution_id.value + '.docx';
|
||||
|
||||
// Crea un nuovo archivio ZIP in cui mettere i file della cartella
|
||||
const newZip = new JSZip();
|
||||
|
||||
// Se una cartella esiste nello ZIP, estrai i file da essa, altrimenti crea una nuova cartella
|
||||
const folder = zip.folder(folderName);
|
||||
if (folder) {
|
||||
// Aggiungi ogni file della cartella al nuovo archivio ZIP
|
||||
const files = folder.files;
|
||||
for (const fileName in files) {
|
||||
const file = files[fileName];
|
||||
|
||||
// Controlla se il file è valido (non nullo)
|
||||
if (file && file.async) {
|
||||
try {
|
||||
const fileContent = await file.async('blob'); // Estrai il contenuto del file
|
||||
newZip.file(fileName, fileContent);
|
||||
} catch (fileError) {
|
||||
console.error(`Error while extracting "${fileName}":`, fileError);
|
||||
}
|
||||
} else {
|
||||
console.warn(`"${fileName}" is invalid or cannot be elaborated`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Se la cartella non esiste, crea una cartella vuota con nome "folderToDownload"
|
||||
newZip.folder(folderName);
|
||||
}
|
||||
|
||||
// Crea il nuovo file ZIP da scaricare
|
||||
const newZipContent = await newZip.generateAsync({ type: 'blob' });
|
||||
const url = URL.createObjectURL(newZipContent);
|
||||
|
||||
// Crea un link per scaricare il file ZIP
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${folderName}.zip`; // Nome del file ZIP che contiene la cartella
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
// Simulazione di un click per scaricare il file
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
// Pulizia del DOM
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error('Error while downloading folder:', error);
|
||||
}
|
||||
};
|
||||
|
||||
async function updateRating(newRating) {
|
||||
|
||||
Reference in New Issue
Block a user