mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
make downloads work via stdio (writing to /dev/local triggers download)
This commit is contained in:
parent
f740ef7733
commit
4d671e3ba3
2 changed files with 38 additions and 11 deletions
|
|
@ -155,14 +155,13 @@ Options:
|
|||
var d = stdio.readAll(fd);
|
||||
if (d != null) {
|
||||
if (download) {
|
||||
var link = document.createElement("a");
|
||||
link.target = '_blank';
|
||||
link.download = fd.node.name;
|
||||
var blob = new Blob([d], {type: "text/plain"});
|
||||
link.href = URL.createObjectURL(blob);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
var ld = stdio.open('/dev/local',false);
|
||||
if (ld) {
|
||||
stdio.write(ld,{name:fd.node.name,data:d});
|
||||
stdio.close(ld);
|
||||
}else{
|
||||
io.error('can not write to local device');
|
||||
}
|
||||
}else{
|
||||
io.write(d);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,16 @@ var clite = {
|
|||
callback(data);
|
||||
});
|
||||
}
|
||||
},
|
||||
download:function(name,data) {
|
||||
var link = document.createElement("a");
|
||||
link.target = '_blank';
|
||||
link.download = name;
|
||||
var blob = new Blob([data], {type: "text/plain"});
|
||||
link.href = URL.createObjectURL(blob);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
},
|
||||
init:function() {
|
||||
|
|
@ -128,7 +138,7 @@ data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`;
|
|||
}
|
||||
n.data.content = data;
|
||||
n.perms = 'cr--r-----';
|
||||
n.isdev = true;
|
||||
n.data.isdev = true;
|
||||
var fd = clite.io.open('/dev/wfs');
|
||||
var l;
|
||||
while ((l = clite.io.readLine(fd)) != null) {
|
||||
|
|
@ -165,7 +175,22 @@ data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`;
|
|||
clite.io.close(fd);
|
||||
// populate /dev (data/filesys.txt is /dev/wfs already)
|
||||
clite.log.write('Populating /dev');
|
||||
// TODO: are there any other devices we need?
|
||||
// writing to /dev/local downloads data {name:'filename to save',data:'file content'}
|
||||
vfsapi.mkFile('/dev/local');
|
||||
var n = vfsapi.getNode('/dev/local');
|
||||
if (!n) {
|
||||
clite.log.write('local device failure');
|
||||
return;
|
||||
}
|
||||
n.data.content = {
|
||||
read:null,
|
||||
write:function(obj) {
|
||||
clite.core.download(obj.name,obj.data);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
n.perms = 'crw-rw-rw-';
|
||||
n.data.isdev = true;
|
||||
// populate /bin
|
||||
clite.log.write('Populating /bin');
|
||||
// create a temporary function to load in commands
|
||||
|
|
@ -424,7 +449,10 @@ clite.io = {
|
|||
clite.io.write = function(fd,data) {
|
||||
if (!fd.canwrite)
|
||||
return false;
|
||||
if (typeof fd.data.content != 'string')
|
||||
if (fd.node.data.isdev && typeof data.name === 'string' && typeof data.data === 'string') {
|
||||
return fd.node.data.content.write(data);
|
||||
}
|
||||
if (typeof fd.node.data.content != 'string')
|
||||
return false;
|
||||
if (typeof data != 'string')
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue