From e2ac72336bdc4c1e8a3ba34d81bd843525725315 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Thu, 28 Nov 2019 01:48:39 +0800 Subject: [PATCH] html: use file-saver to save file --- html/package.json | 1 + html/src/components/zmodem/index.tsx | 8 ++++++-- html/yarn.lock | 5 +++++ src/index.html | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/html/package.json b/html/package.json index c4c6d6c..447814b 100644 --- a/html/package.json +++ b/html/package.json @@ -60,6 +60,7 @@ "dependencies": { "backoff": "^2.5.0", "decko": "^1.2.0", + "file-saver": "^2.0.2", "preact": "^10.0.5", "xterm": "^4.2.0", "xterm-addon-fit": "^0.3.0", diff --git a/html/src/components/zmodem/index.tsx b/html/src/components/zmodem/index.tsx index 55e5c32..ca114b8 100644 --- a/html/src/components/zmodem/index.tsx +++ b/html/src/components/zmodem/index.tsx @@ -1,5 +1,6 @@ import { bind } from 'decko'; import { h, Component } from 'preact'; +import { saveAs } from 'file-saver'; import { IDisposable, ITerminalAddon, Terminal } from 'xterm'; import * as Zmodem from 'zmodem.js/src/zmodem_browser'; @@ -76,7 +77,7 @@ export class ZmodemAddon extends Component implements ITerminalAdd @bind private zmodemWrite(data: ArrayBuffer): void { - this.terminal.writeUtf8(new Uint8Array(data)); + this.terminal.write(new Uint8Array(data)); } @bind @@ -132,7 +133,10 @@ export class ZmodemAddon extends Component implements ITerminalAdd }); offer .accept() - .then(() => Zmodem.Browser.save_to_disk(fileBuffer, offer.get_details().name)) + .then(() => { + const blob = new Blob(fileBuffer, { type: 'application/octet-stream' }); + saveAs(blob, offer.get_details().name); + }) .catch(e => handleError(e, 'receive')); }); diff --git a/html/yarn.lock b/html/yarn.lock index 292609a..1a14e27 100644 --- a/html/yarn.lock +++ b/html/yarn.lock @@ -2667,6 +2667,11 @@ figures@^2.0.0: dependencies: escape-string-regexp "^1.0.5" +file-saver@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.2.tgz#06d6e728a9ea2df2cce2f8d9e84dfcdc338ec17a" + integrity sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw== + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" diff --git a/src/index.html b/src/index.html index 8df3d29..2891712 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal \ No newline at end of file +ttyd - Terminal \ No newline at end of file -- 2.43.4