Moved from stream-saver to file-saver
This commit is contained in:
parent
93a8563210
commit
b9993e1a0b
@ -13,7 +13,6 @@
|
||||
"@testing-library/react": "^11.2.0",
|
||||
"@testing-library/user-event": "^12.2.2",
|
||||
"ammo.js": "kripken/ammo.js#aab297a4164779c3a9d8dc8d9da26958de3cb778",
|
||||
"blob-polyfill": "^5.0.20210201",
|
||||
"case": "^1.6.3",
|
||||
"color": "^3.1.3",
|
||||
"comlink": "^4.3.0",
|
||||
@ -22,6 +21,7 @@
|
||||
"dexie-export-import": "^1.0.0",
|
||||
"err-code": "^2.0.3",
|
||||
"fake-indexeddb": "^3.1.2",
|
||||
"file-saver": "^2.0.5",
|
||||
"fuse.js": "^6.4.1",
|
||||
"interactjs": "^1.9.7",
|
||||
"konva": "^7.1.8",
|
||||
@ -52,10 +52,8 @@
|
||||
"simplify-js": "^1.2.4",
|
||||
"socket.io-client": "^3.0.3",
|
||||
"source-map-explorer": "^2.4.2",
|
||||
"streamsaver": "^2.0.5",
|
||||
"theme-ui": "^0.3.1",
|
||||
"use-image": "^1.0.5",
|
||||
"web-streams-polyfill": "^3.0.1",
|
||||
"webrtc-adapter": "^7.5.1"
|
||||
},
|
||||
"resolutions": {
|
||||
|
@ -1,10 +1,7 @@
|
||||
import React, { useRef, useState, useEffect } from "react";
|
||||
import { Box, Label, Text, Button, Flex } from "theme-ui";
|
||||
import * as streamSaver from "streamsaver";
|
||||
import * as streamPonyfill from "web-streams-polyfill/ponyfill";
|
||||
import { saveAs } from "file-saver";
|
||||
import * as Comlink from "comlink";
|
||||
// Polyfill blob to get use to Blob.stream() on unsupported browsers (Safari)
|
||||
import "blob-polyfill";
|
||||
|
||||
import Modal from "../components/Modal";
|
||||
import LoadingOverlay from "../components/LoadingOverlay";
|
||||
@ -14,10 +11,6 @@ import { useDatabase } from "../contexts/DatabaseContext";
|
||||
|
||||
import DatabaseWorker from "worker-loader!../workers/DatabaseWorker"; // eslint-disable-line import/no-webpack-loader-syntax
|
||||
|
||||
// Add writableStream ponyfill
|
||||
streamSaver.WritableStream =
|
||||
streamSaver.WritableStream || streamPonyfill.WritableStream;
|
||||
|
||||
const worker = Comlink.wrap(new DatabaseWorker());
|
||||
|
||||
function ImportDatabaseModal({ isOpen, onRequestClose }) {
|
||||
@ -49,37 +42,13 @@ function ImportDatabaseModal({ isOpen, onRequestClose }) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
const fileStreamRef = useRef();
|
||||
|
||||
async function handleExportDatabase() {
|
||||
setIsLoading(true);
|
||||
backgroundTaskRunningRef.current = true;
|
||||
const blob = await worker.exportData(Comlink.proxy(handleDBProgress));
|
||||
saveAs(blob, `${new Date().toISOString()}.owlbear`);
|
||||
setIsLoading(false);
|
||||
|
||||
const fileStream = streamSaver.createWriteStream(
|
||||
`${new Date().toISOString()}.owlbear`,
|
||||
{
|
||||
size: blob.size,
|
||||
}
|
||||
);
|
||||
fileStreamRef.current = fileStream;
|
||||
|
||||
const readableStream = blob.stream();
|
||||
try {
|
||||
await readableStream.pipeTo(fileStream);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
backgroundTaskRunningRef.current = false;
|
||||
fileStreamRef.current = null;
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
onRequestClose();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@ -90,20 +59,19 @@ function ImportDatabaseModal({ isOpen, onRequestClose }) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleUnload() {
|
||||
if (fileStreamRef.current) {
|
||||
fileStreamRef.current.abort();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
window.addEventListener("unload", handleUnload);
|
||||
return () => {
|
||||
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
window.removeEventListener("unload", handleUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
function handleClose() {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
onRequestClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onRequestClose={handleClose} allowClose={!isLoading}>
|
||||
<Flex
|
||||
|
20
yarn.lock
20
yarn.lock
@ -3145,11 +3145,6 @@ bindings@^1.5.0:
|
||||
dependencies:
|
||||
file-uri-to-path "1.0.0"
|
||||
|
||||
blob-polyfill@^5.0.20210201:
|
||||
version "5.0.20210201"
|
||||
resolved "https://registry.yarnpkg.com/blob-polyfill/-/blob-polyfill-5.0.20210201.tgz#0024bfa5dcc3440eb5a2f1e5991cb1612a558465"
|
||||
integrity sha512-SrH6IG6aXL9pCgSysBCiDpGcAJ1j6/c1qCwR3sTEQJhb+MTk6FITNA6eW6WNYQDNZVi4Z9GjxH5v2MMTv59CrQ==
|
||||
|
||||
bluebird@^3.5.5:
|
||||
version "3.7.2"
|
||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
|
||||
@ -5543,6 +5538,11 @@ file-loader@6.1.1:
|
||||
loader-utils "^2.0.0"
|
||||
schema-utils "^3.0.0"
|
||||
|
||||
file-saver@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
|
||||
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
|
||||
|
||||
file-uri-to-path@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
|
||||
@ -11340,11 +11340,6 @@ stream-shift@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
|
||||
integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==
|
||||
|
||||
streamsaver@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/streamsaver/-/streamsaver-2.0.5.tgz#3212f0e908fcece5b3a65591094475cf87850d00"
|
||||
integrity sha512-KIWtBvi8A6FiFZGNSyuIZRZM6C8AvnWTiCx/TYa7so420vC5sQwcBKkdqInuGWoWMfeWy/P+/cRqMtWVf4RW9w==
|
||||
|
||||
strict-uri-encode@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
|
||||
@ -12398,11 +12393,6 @@ wbuf@^1.1.0, wbuf@^1.7.3:
|
||||
dependencies:
|
||||
minimalistic-assert "^1.0.0"
|
||||
|
||||
web-streams-polyfill@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.0.1.tgz#1f836eea307e8f4af15758ee473c7af755eb879e"
|
||||
integrity sha512-M+EmTdszMWINywOZaqpZ6VIEDUmNpRaTOuizF0ZKPjSDC8paMRe/jBBwFv0Yeyn5WYnM5pMqMQa82vpaE+IJRw==
|
||||
|
||||
webidl-conversions@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
|
||||
|
Loading…
Reference in New Issue
Block a user