improved upload-cmd
This commit is contained in:
parent
938d1bc229
commit
1b5cf3febb
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 ){
|
||||
|
|
Loading…
Reference in New Issue