From 1b5cf3febbb0f451003c56d4579294ca57e447f0 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Fri, 17 Jan 2025 18:00:49 +0100 Subject: [PATCH] improved upload-cmd --- com/isoterminal.js | 6 ++++++ com/isoterminal/feat/httpfs.js | 38 ++++++++++++++++++++++++++++------ com/isoterminal/feat/term.js | 2 +- com/selfcontainer.js | 3 ++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/com/isoterminal.js b/com/isoterminal.js index 116165f..0e32b44 100644 --- a/com/isoterminal.js +++ b/com/isoterminal.js @@ -351,6 +351,12 @@ if( typeof AFRAME != 'undefined '){ instance.setAttribute("dom", "") instance.setAttribute("pastedrop", "") + + // *REMOVE* make a boot-plugin mechanism in feat/term.js + this.term.addEventListener('enable-console', () => { + instance.dom.classList.remove('blink') + }) + this.term.addEventListener('ready', (e) => { instance.dom.classList.remove('blink') this.term.emit('status',"running") diff --git a/com/isoterminal/feat/httpfs.js b/com/isoterminal/feat/httpfs.js index 3557937..e40e58f 100644 --- a/com/isoterminal/feat/httpfs.js +++ b/com/isoterminal/feat/httpfs.js @@ -4,26 +4,52 @@ if( typeof emulator != 'undefined' ){ ISOTerminal.addEventListener('ready', function(e){ + function getMimeType(file) { + const mimeTypes = { + jpg: 'image/jpeg', + jpeg: 'image/jpeg', + png: 'image/png', + mp4: 'video/mp4', + gif: 'image/gif', + }; + + const extension = file.split('.').pop().toLowerCase(); + return mimeTypes[extension] || 'application/octet-stream'; // Fallback + } + // listen for http request to the filesystem ( file://host/path ) xhook.before( (request,callback) => { - - if (request.url.match(/^file:\/\/xrsh\/mnt\/.*/) ){ + console.log(request.url) + if (request.url.match(/^\/mnt\/.*/) ){ let response - let file = request.url.replace(/^file:\/\/xrsh\/mnt\//,'') + let file = request.url.replace(/^\/mnt\//,'') + let mimetype = getMimeType(file) this.worker.read_file_world(file) .then( (data) => { - response = new Response( new Blob( [data] ) ) // wrap Uint8Array into array - response.status = 200 + if( data == null ) throw `/mnt/${file} does not exist in ISO filesystem`" + let blob = new Blob( [data], {type: getMimeType(file) }) // wrap Uint8Array into array + response = { + headers: new Headers({ 'Content-Type': getMimeType(file) }), + data, + url: file, + status: 200, + blob: () => new Promise( (resolve,reject) => resolve(blob) ), + arrayBuffer: blob.arrayBuffer + } + console.log("serving from iso filesystem: "+file) + console.log("*TODO* large files being served partially") callback(response) }) .catch( (e) => { + console.error(e) response = new Response() response.status = 404 callback(response) }) return + }else{ + callback() } - callback() }) }) diff --git a/com/isoterminal/feat/term.js b/com/isoterminal/feat/term.js index ad9245b..faa721d 100644 --- a/com/isoterminal/feat/term.js +++ b/com/isoterminal/feat/term.js @@ -91,7 +91,7 @@ ISOTerminal.prototype.TermInit = function(){ }else{ if( (ch == "\n" || ch == "\r") && typeof this.console == 'undefined' ){ switch( this.lastChar ){ - case '1': this.bootISO(); break; + case '1': this.bootISO(); break; case '2': { this.emit('enable-console',{stdout:true}) this.emit('status',"javascript console") diff --git a/com/selfcontainer.js b/com/selfcontainer.js index 322cc4f..97169c8 100644 --- a/com/selfcontainer.js +++ b/com/selfcontainer.js @@ -47,7 +47,8 @@ AFRAME.registerComponent('selfcontainer', { cb(res) }else{ - if( request.url.match(/(^file:\/\/xrsh)/) ) return cb(response) + // never cache requests to filesystem + if( request.url.match(/(^\/mnt\/)/) ) return cb(response) console.log("selfcontainer.js: caching "+request.url) if( response.text ){