MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / uploadFile

Function uploadFile

web/scripts/ragnar_modern.js:13504–13549  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13502async function handlePwnSwap(targetMode) {
13503 const normalized = targetMode === 'pwnagotchi' ? 'pwnagotchi' : 'ragnar';
13504
13505 if (normalized === 'pwnagotchi' && !pwnStatus.installed) {
13506 addConsoleMessage('Install Pwnagotchi before swapping', 'warning');
13507 return;
13508 }
13509
13510 const buttonId = normalized === 'pwnagotchi' ? 'pwn-swap-to-pwn-btn' : 'pwn-swap-to-ragnar-btn';
13511 const button = document.getElementById(buttonId);
13512 if (button) {
13513 button.disabled = true;
13514 button.textContent = 'Scheduling switch...';
13515 button.classList.add('opacity-60', 'cursor-not-allowed');
13516 }
13517
13518 try {
13519 const result = await postPwnAPI('/api/pwnagotchi/swap', { target: normalized });
13520 if (normalized === 'pwnagotchi') _pwnSwapRequestedThisSession = true;
13521 const message = (result && result.message) ? result.message : `Switch scheduled to ${formatPwnModeLabel(normalized)}`;
13522 addConsoleMessage(message, 'info');
13523 if (result && result.status) {
13524 updatePwnagotchiUI(result.status);
13525 } else {
13526 refreshPwnagotchiStatus({ silent: true });
13527 }
13528 } catch (error) {
13529 console.error('Failed to schedule Pwnagotchi swap:', error);
13530 addConsoleMessage(`Swap failed: ${error.message}`, 'error');
13531 } finally {
13532 updatePwnButtons();
13533 }
13534}
13535
13536async function postPwnAPI(endpoint, payload = {}) {
13537 const response = await fetch(endpoint, {
13538 method: 'POST',
13539 headers: {
13540 'Content-Type': 'application/json'
13541 },
13542 body: JSON.stringify(payload)
13543 });
13544
13545 let data = null;
13546 try {
13547 data = await response.json();
13548 } catch (error) {
13549 data = null;
13550 }
13551
13552 if (!response.ok || (data && data.success === false)) {

Callers

nothing calls this directly

Calls 6

appendMethod · 0.80
showFileLoadingFunction · 0.70
networkAwareFetchFunction · 0.70
showFileSuccessFunction · 0.70
refreshFilesFunction · 0.70
showFileErrorFunction · 0.70

Tested by

no test coverage detected