Deploy minified webusb build
This commit is contained in:
commit
00874549ed
7 files changed
+3
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 502 B |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1 @@
|
||||
@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}@keyframes pulse{0%,to{transform:scale(1)}50%{transform:scale(1.1)}}.download-spinner-text-wrap{display:flex;align-items:center;flex:1;min-width:0}#downloadSpinnerText{overflow-x:auto;white-space:nowrap;display:block;min-width:0;flex:1;scrollbar-width:none}#downloadSpinnerText::-webkit-scrollbar{display:none}#downloadSpinnerSpeed{flex-shrink:0;margin-left:12px;color:#32ffcf}.spinner{width:32px;height:32px;border:4px solid #163951;border-top:4px solid #32ffcf;border-radius:50%;animation:spin 1s linear infinite;margin-right:15px;display:inline-block;vertical-align:middle}.custom-select{background:linear-gradient(45deg,#32ffcf,#5cbeff);color:#111f28;border:0;padding:14px 26px;border-radius:8px;cursor:pointer;font-size:16px;font-weight:600;transition:transform .2s,box-shadow .2s;margin:5px;min-height:48px;appearance:none;-webkit-appearance:none;-moz-appearance:none;box-shadow:0 5px 15px rgba(50,255,207,.08)}.custom-select:focus{outline:0;box-shadow:0 0 0 2px #32ffcf}.custom-select option{background:#143144;color:#32ffcf;font-weight:600;font-size:16px}body{font-family:"Segoe UI",Tahoma,Geneva,Verdana,sans-serif;max-width:800px;margin:0 auto;padding:20px;background:linear-gradient(135deg,#111f28 0,#0b1519 100%);min-height:100dvh;min-height:-webkit-fill-available;color:#fbfbfb}.container{background:#143144;border-radius:15px;padding:20px;box-shadow:0 20px 40px rgba(0,0,0,.3);border:1px solid #335e77}@media (max-width:768px){body{padding:12px}.container{padding:15px;border-radius:12px}}.unsupported-splash{text-align:center;padding:30px 15px;background:#122430;border-radius:15px;border:2px solid #fa3a5d}.unsupported-splash h2{color:#fa3a5d;font-size:1.8em;margin-bottom:15px}.unsupported-splash p{font-size:1em;line-height:1.5;margin-bottom:12px;color:#bed0d6}.browser-link,button{background:linear-gradient(45deg,#32ffcf,#5cbeff);color:#111f28;border-radius:8px;font-weight:600;transition:transform .2s,box-shadow .2s}.browser-link{display:inline-block;padding:12px 24px;text-decoration:none;margin-top:15px}.browser-link:hover,button:hover{transform:translateY(-2px);box-shadow:0 5px 15px rgba(50,255,207,.4)}h1{text-align:center;margin-bottom:25px;background:linear-gradient(45deg,#32ffcf,#69ff8f);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;font-size:2.2em}@media (max-width:768px){h1{font-size:1.8em;margin-bottom:20px}.unsupported-splash{padding:20px 12px}.unsupported-splash h2{font-size:1.5em}}.section{margin-bottom:20px;padding:15px;border-radius:10px;background:#122430;border-left:4px solid #32ffcf}@media (max-width:768px){.section{padding:12px;margin-bottom:15px}}button{border:0;padding:14px 26px;cursor:pointer;font-size:16px;margin:5px;min-height:48px}@media (max-width:768px){button{width:100%;margin:8px 0;padding:16px}}button:disabled{background:#335e77;color:#bed0d6;cursor:not-allowed;transform:none}.device-info,.status{padding:10px;border-radius:5px;margin:10px 0;font-size:.95em}.status.success{background-color:rgba(105,255,143,.2);color:#69ff8f;border:1px solid #69ff8f}.status.error{background-color:rgba(250,58,93,.2);color:#fa3a5d;border:1px solid #fa3a5d}.status.info{background-color:rgba(92,190,255,.2);color:#5cbeff;border:1px solid #5cbeff}.device-info{background:#0b1519;padding:12px;border-radius:8px;border:1px solid #163951;color:#bed0d6;overflow-wrap:break-word}.transfer-text{color:#32ffcf;font-weight:600}.log{background:#071013;color:#bed0d6;padding:12px;border-radius:8px;font-family:"Courier New",monospace;max-height:200px;overflow-y:auto;margin-top:12px;border:1px solid #163951;white-space:pre-wrap;font-size:.9em}h3{color:#32ffcf;margin-top:0;font-size:1.3em}@media (max-width:768px){h3{font-size:1.2em}}.log-controls{display:flex;justify-content:flex-end;margin-top:10px;flex-wrap:wrap}.log-btn{background:#163951;color:#bed0d6;padding:8px 12px;font-size:14px;margin:4px;min-height:36px}.file-queue{margin-top:15px;background:#0b1519;border-radius:8px;padding:12px;border:1px solid #163951}.file-item{display:flex;justify-content:space-between;align-items:center;padding:10px;border-bottom:1px solid #163951;flex-wrap:wrap}.file-item:last-child{border-bottom:none}.file-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;margin-right:8px}.file-size{color:#bed0d6;margin:0 8px;font-size:.9em;white-space:nowrap}.file-actions{display:flex;gap:8px;flex-shrink:0}.queue-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;flex-wrap:wrap}.queue-title{font-weight:600;color:#32ffcf;margin-right:10px}.queue-count{background:#163951;color:#bed0d6;padding:4px 10px;border-radius:10px;font-size:.9em}.btn-remove{background:#ff3232;color:#fff;border:0;border-radius:4px;padding:6px 10px;cursor:pointer;font-size:13px;min-height:32px}.file-controls{display:flex;gap:10px;margin-top:10px;flex-wrap:wrap}@media (max-width:768px){.file-controls{flex-direction:coluLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>Sphaira WebUSB File Transfer</title><link rel="icon" type="image/png" sizes="16x16" href="assets/icon_16.png"><link rel="icon" type="image/png" sizes="32x32" href="assets/icon_32.png"><link rel="icon" type="image/png" sizes="48x48" href="assets/icon_48.png"><link rel="apple-touch-icon" sizes="180x180" href="assets/icon_180.png"><link rel="stylesheet" href="index.css"></head><body><div class="container"><h1>Sphaira WebUSB File Transfer</h1><div id="connectionToast" class="connection-toast"><span class="toast-icon">🔗</span> <span id="toastMessage">Device Connected</span> <button class="toast-close" id="toastClose">×</button></div><div class="section"><h3>Step 1: Connect USB Device</h3><button id="connectBtn">Connect New USB Device</button> <button id="disconnectBtn" disabled="disabled">Disconnect</button><div id="authorizedDevices" class="device-list" style="display:none"><h4 style="color:#32ffcf;margin-top:0">Previously Authorized Devices:</h4><div id="deviceListContainer"></div></div></div><div class="section"><h3>Step 2: Select Mode</h3><label for="modeSelect" style="font-weight:600;color:#bed0d6">Choose transfer mode:</label> <select id="modeSelect" class="custom-select" style="margin-left:10px"><option value="upload">Upload (PC → Switch)</option><option value="download">Download (Switch → PC)</option></select></div><div class="section" id="uploadStep3Section"><h3>Step 3: Select Files to Transfer</h3><input type="file" id="fileInput" accept=".nsp, .xci, .nsz, .xcz" multiple="multiple" class="hidden"><div class="file-controls"><button id="addFilesBtn" class="btn-add" disabled="disabled">Add Files</button> <button id="clearQueueBtn" class="btn-clear" disabled="disabled">Clear Queue</button></div><div class="file-queue"><div class="queue-header"><span class="queue-title">File Queue</span> <span class="queue-count" id="fileCount">0 files</span></div><div id="fileQueueList"></div></div></div><div class="section" id="downloadStep3Section" style="display:none"><h3>Step 3: Select Download Destination</h3><button id="pickFolderBtn" class="btn-add">Pick Folder</button> <span id="selectedFolderName" style="margin-left:10px;color:#5cbeff"></span></div><div class="section" id="uploadStep4Section"><h3>Step 4: Transfer Files</h3><button id="sendBtn" disabled="disabled">Send Files</button><div id="transferProgress" class="device-info" style="display:none"><div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px"><span id="progressTitle"><strong>Transfer Progress</strong></span> <span id="progressCounter" style="color:#32ffcf;font-weight:600">0 / 0</span></div><div class="progress-bar-container" style="margin-bottom:10px"><div class="progress-bar" style="height:8px;background:#163951;border-radius:4px;overflow:hidden"><div id="fileProgressBar" style="height:100%;width:0%;background:linear-gradient(90deg,#32ffcf,#5cbeff);transition:width .3s ease"></div></div><div style="display:flex;justify-content:space-between;font-size:.8em;margin-top:4px"><span id="progressPercentage">0%</span> <span id="transferSpeed">0 MB/s</span></div></div><div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;font-size:.85em"><div><span style="color:#bed0d6">Time Spent:</span> <span id="timeSpent" style="color:#5cbeff;margin-left:5px">00:00</span></div><div><span style="color:#bed0d6">Time Remaining:</span> <span id="timeRemaining" style="color:#ffaa32;margin-left:5px">--:--</span></div><div><span style="color:#bed0d6">Data Transferred:</span> <span id="dataTransferred" style="color:#69ff8f;margin-left:5px">0 MB</span></div><div><span style="color:#bed0d6">Speed:</span> <span id="currentSpeed" style="color:#32ffcf;margin-left:5px">0 MB/s</span></div></div></div></div><div class="section" id="downloadStep4Section" style="display:none"><h3>Step 4: Download Files</h3><div id="downloadSpinner" style="display:none;align-items:center;gap:10px;margin:18px 0 0 0;font-size:1.1em"><span class="spinner"></span><div id="downloadSpinnerTextWrap" style="display:flex;align-items:center;flex:1;min-width:0"><span id="downloadSpinnerText" style="overflow-x:auto;white-space:nowrap;display:block;min-width:0;flex:1"></span> <span id="downloadSpinnerSpeed" style="flex-shrink:0;margin-left:12px;color:#32ffcf"></span></div></div></div><div class="section"><h3>Logs</h3><div id="logDiv" class="log"></div><div class="log-controls"><button id="clearLogBtn" class="log-btn">Clear Log</button> <button id="copyLogBtn" class="log-btn">Copy Log</button></div></div></div><script src="index.js"></script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
const MAGIC=1397770288,PACKET_SIZE=24,CMD_QUIT=0,CMD_OPEN=1,CMD_EXPORT=1,RESULT_OK=0,RESULT_ERROR=1,FLAG_NONE=0,FLAG_STREAM=1;class UsbPacket{constructor(e=MAGIC,t=0,s=0,n=0,i=0,o=0){this.magic=e,this.arg2=t,this.arg3=s,this.arg4=n,this.arg5=i,this.crc32c=o}toBuffer(){const e=new ArrayBuffer(24),t=new DataView(e);return t.setUint32(0,this.magic,!0),t.setUint32(4,this.arg2,!0),t.setUint32(8,this.arg3,!0),t.setUint32(12,this.arg4,!0),t.setUint32(16,this.arg5,!0),t.setUint32(20,this.crc32c,!0),e}static fromBuffer(e){const t=new DataView(e);return new this(t.getUint32(0,!0),t.getUint32(4,!0),t.getUint32(8,!0),t.getUint32(12,!0),t.getUint32(16,!0),t.getUint32(20,!0))}calculateCrc32c(){const e=this.toBuffer(),t=new Uint8Array(e,0,20);return crc32c(0,t)}generateCrc32c(){this.crc32c=this.calculateCrc32c()}verify(){if(this.crc32c!==this.calculateCrc32c())throw new Error("CRC32C mismatch");if(this.magic!==MAGIC)throw new Error("Bad magic");return!0}}class SendPacket extends UsbPacket{static build(e,t=0,s=0){const n=new SendPacket(MAGIC,e,t,s);return n.generateCrc32c(),n}getCmd(){return this.arg2}}class ResultPacket extends UsbPacket{static build(e,t=0,s=0){const n=new ResultPacket(MAGIC,e,t,s);return n.generateCrc32c(),n}verify(){if(super.verify(),0!==this.arg2)throw new Error("Result not OK");return!0}}class SendDataPacket extends UsbPacket{static build(e,t,s){const n=Number(BigInt(e)>>32n&0xFFFFFFFFn),i=Number(0xFFFFFFFFn&BigInt(e)),o=new SendDataPacket(MAGIC,n,i,t,s);return o.generateCrc32c(),o}getOffset(){return Number(BigInt(this.arg2)<<32n|BigInt(this.arg3))}getSize(){return this.arg4}getCrc32c(){return this.arg5}}const crc32c=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let s=t;for(let e=0;e<8;e++)s=1&s?s>>>1^2197175160:s>>>1;e[t]=s>>>0}return function(t,s){t^=4294967295;let n=0;const i=s.length;for(;n<i-3;n+=4)t=e[255&(t^s[n])]^t>>>8,t=e[255&(t^s[n+1])]^t>>>8,t=e[255&(t^s[n+2])]^t>>>8,t=e[255&(t^s[n+3])]^t>>>8;for(;n<i;n++)t=e[255&(t^s[n])]^t>>>8;return(4294967295^t)>>>0}})();class WebUSBFileTransfer{maybeStartDownloadLoop(){"download"===document.getElementById("modeSelect").value&&this.isConnected&&this.selectedDownloadDirHandle&&!this.downloadLoopActive&&this.startDownloadLoop()}async startDownloadLoop(){if(!this.downloadLoopActive){if(this.downloadLoopActive=!0,!this.selectedDownloadDirHandle)return this.showToast("No download folder selected.","error",4e3),void(this.downloadLoopActive=!1);if(!this.isConnected)return this.showToast("Device not connected.","error",4e3),void(this.downloadLoopActive=!1);this.log("Starting download command loop...");try{for(;;){const[e,t,s]=await this.get_send_header();if(0===e){await this.send_result(0),this.log("Received CMD_QUIT, exiting download loop.");break}if(1!==e){await this.send_result(1),this.log(`Unknown command (${e}), exiting.`);break}{await this.send_result(0);const e=new Uint8Array(await this.read(t).then(e=>e.data.buffer)),s=new TextDecoder("utf-8").decode(e);this.log(`Receiving file: ${s}`);const n=await this.createFileInDir(this.selectedDownloadDirHandle,s);console.log(`Created file handle for: ${s}`),await this.send_result(0),console.log("Acknowledged file creation, starting data transfer..."),await this.downloadFileData(n)}}}catch(e){this.log("Download loop error: "+e.message),this.showToast("Download failed: "+e.message,"error",5e3)}finally{this.downloadLoopActive=!1}}}sanitizePathSegment(e){return e&&"."!==e&&".."!==e?e.replace(/[\\/:*?"<>|]/g,"_"):null}async createFileInDir(e,t){this.log(`Creating file in directory: ${t}`);const s=t.split("/");let n=e;for(let e=0;e<s.length-1;e++){this.log(`Creating/entering directory: ${s[e]}`);const t=this.sanitizePathSegment(s[e]);t?(console.log(`Processing directory segment: ${t}`),n=await n.getDirectoryHandle(t,{create:!0}),console.log(`Entered directory: ${t}`)):console.log(`Skipping invalid directory segment: ${s[e]}`)}console.log(`Finalizing file creation for: ${s[s.length-1]}`);const i=this.sanitizePathSegment(s[s.length-1]);if(!i)throw new Error("Invalid file name");return console.log(`Creating file: ${i}`),await n.getFileHandle(i,{create:!0})}async downloadFileData(e){this.log("Starting file data transfer...");const t=await e.createWritable();let s=0,n=0,i=Date.now(),o=i,a=0,r=e.name||"file";for(this.showDownloadSpinner(r,0);;){const[e,d,c]=await this.get_send_data_header();if(await this.send_result(0),0===e&&0===d)break;const l=await this.read(d),h=new Uint8Array(l.data.buffer,l.data.byteOffset,l.data.byteLength),u=crc32c(0,h)>>>0;if(c!==u){this.log(`CRC32C mismatch at offset ${e}: want ${c}, got ${u}`),await this.send_result(1);continue}e===s?(await t.write(h),s+=h.length):await t.write({type:"write",position:e,data:h}),n=Math.max(n,e+h.length);const g=Date.now();if(g-o>200){const e=(g-i)/1e3,t=e>0?n/e:0;this.updateDownloadSpinner(r,t),o=g,a=n}await this.send_result(0)}this.updateDownloadSpinner(r,0,!0),await t.close(),this.hideDownloadSpinner(),this.log("File written successfully.")}showDownlLine truncated
|
||||
Reference in new issue
Block a user