📥 Add functionality to download individual and multiple files from the server
This commit is contained in:
@@ -131,7 +131,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<button @click="downloadAllFromServer" class="btn btn-primary">
|
||||||
📦 Download All from Server
|
📦 Download All from Server
|
||||||
</button>
|
</button>
|
||||||
@@ -286,7 +290,7 @@ async function saveToServer() {
|
|||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
saveSuccess.value = true;
|
saveSuccess.value = true;
|
||||||
console.log('✅ Files saved to server:', result);
|
console.log('✅ Files saved to server:', result);
|
||||||
|
|
||||||
// Reload server status
|
// Reload server status
|
||||||
await loadServerStatus();
|
await loadServerStatus();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -317,6 +321,41 @@ function downloadAll() {
|
|||||||
setTimeout(() => downloadMoves(), 1000);
|
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) {
|
function formatDate(dateString) {
|
||||||
if (!dateString || dateString === 'Never') return 'Never';
|
if (!dateString || dateString === 'Never') return 'Never';
|
||||||
return new Date(dateString).toLocaleString();
|
return new Date(dateString).toLocaleString();
|
||||||
|
|||||||
Reference in New Issue
Block a user