Update downloadFile and resetStore

This commit is contained in:
2025-07-10 17:19:38 +02:00
parent 461d8a3d62
commit 9d44b21868
4 changed files with 102 additions and 60 deletions

View File

@@ -4,13 +4,6 @@
</div>
<div v-else>
<div class="flex items-center justify-between p-2">
<!-- <Button
@click="back()"
label="Load"
class="flex items-center text-sm">
<ChevronLeftIcon name="chevron-left" class="w-4 h-5 text-white"/>
<span>Back to Scenarios</span>
</Button> -->
</div>
</div>
@@ -39,24 +32,15 @@
<th v-if="index === 'MultiFileUpload'" class="border border-gray-300 px-4 py-2">Files Uploaded</th>
<th v-else-if="index === 'SingleFileUpload'" class="border border-gray-300 px-4 py-2 bg-gray-500 text-white">Parameter</th>
<th v-else-if="index === 'input_multiselect_name'">
{{ (scenario.inputs && Array.isArray(scenario.inputs) ? scenario.inputs.find((i) => i.name === 'input_multiselect')?.label : null)}}
{{ scenario.inputs && Array.isArray(scenario.inputs) ? scenario.inputs.find((i) => i.name === 'input_multiselect')?.label : null }}
</th>
<th v-else class="border border-gray-300 px-4 py-2">
{{ index.replace(/_/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase()) }}
</th>
<td class="border border-gray-300 px-4 py-2">
<div v-if="index === 'MultiFileUpload'">
<div v-if="fileNames.length">
<ul>
<li v-for="(file, idx) in fileNames" :key="idx" class="file-item">
{{ file.substring(file.lastIndexOf('/') + 1) }}
<Button icon="pi pi-download" class="p-button-text p-button-sm" label="Download" @click="downloadFileInput(file)" />
</li>
</ul>
</div>
<div v-else>
<p>No files found in the zip.</p>
</div>
{{ filteredInputs.SingleFileUpload.replace(/\\/g, '/').split('/').pop() }}
<Button icon="pi pi-download" class="p-button-text p-button-sm" label="Download" @click="downloadFile(inputs['SingleFileUpload'])" />
</div>
<div v-else-if="index !== 'SingleFileUpload'">{{ input }}</div>
</td>
@@ -110,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(scenario_output)" />
<Button icon="pi pi-download" class="p-button-text p-button-sm" label="Download" @click="downloadFile(inputs['SingleFileUpload'])" />
</li>
</ul>
</div>
@@ -198,6 +182,7 @@ const updateLoading = ref(false);
const fileContent = ref('');
const fileType = ref('');
const chat_enabled = ref(false);
const baseUploadDir = 'mnt/hermione_storage/documents/file_input_scenarios/';
onMounted(() => {
if (execution) {
@@ -210,7 +195,6 @@ onMounted(() => {
});
const retrieveScenarioExec = (id) => {
//const id = execution_id.value.id;
loading.value = true;
axios.get('/execution?id=' + id).then((response) => {
@@ -224,8 +208,8 @@ const retrieveScenarioExec = (id) => {
inputs.value = response.data.scenarioExecutionInput.inputs;
steps.value = response.data.scenario.steps;
if (inputs.value['MultiFileUpload']) {
extractFiles(inputs.value['MultiFileUpload'], 'input', zipInput);
if (steps.value[0].attributes['codegenie_output_type']) {
extractFiles(inputs.value['MultiFileUpload'], 'input', zipInput);
if (steps.value[0].attributes['codegenie_output_type'] == 'FILE') {
fileType.value = 'FILE';
} else if (steps.value[0].attributes['codegenie_output_type'] == 'MARKDOWN') {
@@ -380,34 +364,29 @@ const downloadFileOutput = async (fileName) => {
}
};
const downloadFile = (base64String) => {
// Decodifica la stringa Base64
const binaryString = atob(base64String);
const binaryLength = binaryString.length;
const bytes = new Uint8Array(binaryLength);
const downloadFile = async (filePath) => {
try {
let relativePath = filePath;
if (filePath.startsWith(baseUploadDir)) {
relativePath = filePath.substring(baseUploadDir.length);
}
for (let i = 0; i < binaryLength; i++) {
bytes[i] = binaryString.charCodeAt(i);
console.log('Original path:', filePath);
console.log('Relative path:', relativePath);
// Chiamata all'API backend per ottenere il file
await scenario_execution_store.downloadFile(relativePath, execution_id.value);
} catch (error) {
console.error('Error downloading file:', error);
// Notifica di errore
toast.add({
severity: 'error',
summary: 'Error',
detail: 'Error downloading file. Please try again.',
life: 3000
});
}
// Creazione di un Blob dal file binario
const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
// Creazione di un URL per il Blob
const url = URL.createObjectURL(blob);
// Creazione di un elemento anchor per il download
const link = document.createElement('a');
link.href = url;
link.download = 'sf_document-' + execution_id.value + '.docx';
// Simulazione di un click per scaricare il file
document.body.appendChild(link);
link.click();
// Pulizia del DOM
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
const downloadFolderFromBase64 = async (base64String) => {

View File

@@ -80,6 +80,7 @@ import { useRouter } from 'vue-router';
import { LoadingStore } from '../../stores/LoadingStore.js';
import { UserPrefStore } from '../../stores/UserPrefStore.js';
import { ScenarioStore } from '../../stores/ScenarioStore.js';
import { ScenarioExecutionStore } from '../../stores/ScenarioExecutionStore.js';
const loadingStore = LoadingStore()
@@ -87,6 +88,7 @@ const userPrefStore = UserPrefStore();
const auth = useAuth();
const user = computed(() => auth.user());
const scenario_store = ScenarioStore();
const scenario_execution_store = ScenarioExecutionStore();
const router = useRouter()
@@ -125,6 +127,7 @@ const scenario_store = ScenarioStore();
try {
// Esegui l'update del progetto
scenario_store.resetStore();
scenario_execution_store.resetStore();
await userPrefStore.updateSelectedProject(project);
console.log('Progetto aggiornato e dati utente ricaricati');