webterm: support downloading files

For %sav and %sag blits.
This commit is contained in:
fang 2020-11-06 13:47:22 +01:00
parent 7a40b1137e
commit f950d710c3
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
4 changed files with 30 additions and 6 deletions

View File

@ -1,6 +1,7 @@
:: blit: runtime blit structure
::
~% %mar-blit ..is ~
/+ base64
::
|_ =blit:dill
++ grad %noun
:: +grab: convert from
@ -12,7 +13,6 @@
:: +grow: convert to
::
++ grow
~% %blit-grow ..grow ~
|%
++ noun blit
++ json
@ -25,9 +25,19 @@
%hop (numb p.blit)
%lin s+(crip (tufa p.blit))
%mor b+&
%sag (pairs 'path'^(path p.blit) 'file'^s+(jam q.blit) ~)
%sav (pairs 'path'^(path p.blit) 'file'^s+q.blit ~)
%url s+p.blit
::
%sag
%- pairs
:~ 'path'^(path p.blit)
'file'^s+(en:base64 (as-octs:mimes:html (jam q.blit)))
==
::
%sav
%- pairs
:~ 'path'^(path p.blit)
'file'^s+(en:base64 (as-octs:mimes:html q.blit))
==
::
%klr
:- %a

View File

@ -4876,6 +4876,11 @@
}
}
},
"file-saver": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.2.tgz",
"integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw=="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",

View File

@ -15,6 +15,7 @@
"classnames": "^2.2.6",
"codemirror": "^5.55.0",
"css-loader": "^3.5.3",
"file-saver": "^2.0.2",
"formik": "^2.1.4",
"lodash": "^4.17.15",
"markdown-to-jsx": "^6.11.4",

View File

@ -1,4 +1,5 @@
import Share from './components/lib/sole';
import { saveAs } from 'file-saver';
export default class Store {
constructor() {
this.state = this.initialState();
@ -42,7 +43,14 @@ export default class Store {
this.state.lines.push('');
this.setState({ lines: this.state.lines });
break;
//TODO file downloads for %sag and %sav
case 'sag':
blit.sav = blit.sag;
case 'sav':
let name = blit.sav.path.split('/').slice(-2).join('.');
let buff = new Buffer(blit.sav.file, 'base64');
let blob = new Blob([buff], {type: 'application/octet-stream'});
saveAs(blob, name);
break;
case 'url':
//TODO too invasive? just print as <a>?
window.open(blit.url);