📥 Add functionality to download individual and multiple files from the server
This commit is contained in:
@@ -131,7 +131,11 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="serverStatus.totalFiles > 0" class="button-group" style="margin-top: 1rem;">
|
||||
<div
|
||||
v-if="serverStatus.totalFiles > 0"
|
||||
class="button-group"
|
||||
style="margin-top: 1rem"
|
||||
>
|
||||
<button @click="downloadAllFromServer" class="btn btn-primary">
|
||||
📦 Download All from Server
|
||||
</button>
|
||||
@@ -317,6 +321,41 @@ function downloadAll() {
|
||||
setTimeout(() => downloadMoves(), 1000);
|
||||
}
|
||||
|
||||
async function downloadFromServer(filename) {
|
||||
try {
|
||||
const response = await fetch(`/api/gamemaster/download/${filename}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to download ${filename}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
error.value = `Failed to download ${filename}: ${err.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadAllFromServer() {
|
||||
const filesToDownload = [
|
||||
'pokemon.json',
|
||||
'pokemon-allFormsCostumes.json',
|
||||
'pokemon-moves.json'
|
||||
];
|
||||
|
||||
for (let i = 0; i < filesToDownload.length; i++) {
|
||||
setTimeout(() => {
|
||||
downloadFromServer(filesToDownload[i]);
|
||||
}, i * 500);
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString || dateString === 'Never') return 'Never';
|
||||
return new Date(dateString).toLocaleString();
|
||||
|
||||
Reference in New Issue
Block a user