cambio random del pwa

This commit is contained in:
2025-08-29 16:02:04 -06:00
parent 3a9c8a6e74
commit b07947b9d3
4 changed files with 72 additions and 2 deletions

View File

@@ -22,7 +22,7 @@
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed, ref, onMounted } from 'vue';
interface PlayerRow {
sessionId: string;
@@ -195,7 +195,7 @@ async function downloadNameManagerState() {
const data = await response.json();
const jsonString = JSON.stringify(data, null, 2);
const blob = new Blob([jsonString], { type: 'application/json;charset=utf-8;' });
const blob = new Blob([jsonString], { type: 'application/x-snatchsave' });
const url = URL.createObjectURL(blob);
const now = new Date();
const pad = (n: number) => String(n).padStart(2, '0');
@@ -269,6 +269,36 @@ async function handleFileUpload(event: Event) {
target.value = '';
}
}
// Helper: import NameManager state from JSON text (used by PWA file handler)
async function importNameManagerFromText(text: string) {
try {
const data = JSON.parse(text);
const apiBase = (import.meta as any).env?.VITE_API_URL || `${window.location.protocol}//${window.location.host}/api`;
const response = await fetch(`${apiBase}/admin/namemanager/import`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(`Failed to upload nameManager state: ${response.status}`);
const result = await response.json();
const message = result.importedUuids
? `Estado cargado exitosamente. ${result.importedUuids} UUIDs importados. ${result.message || ''}`
: `Estado cargado exitosamente. ${result.message || 'NameManager actualizado.'}`;
alert(message);
} catch (e) {
alert('Error al procesar el archivo .snatchSave');
}
}
// If PWA was launched with a .snatchSave file, auto-import here
onMounted(async () => {
const pending = localStorage.getItem('snatch.pendingSnatchSave');
if (pending) {
localStorage.removeItem('snatch.pendingSnatchSave');
await importNameManagerFromText(pending);
}
});
</script>
<style scoped>