-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out viewer and re-write unzipping
- Loading branch information
Showing
7 changed files
with
294 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
"bloompub", | ||
"octokit", | ||
"repos", | ||
"toastify" | ||
"toastify", | ||
"unzipper", | ||
"wordmark" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import * as fs from "fs"; | ||
import * as unzipper from "unzipper"; | ||
import * as temp from "temp"; | ||
import * as Path from "path"; | ||
|
||
temp.track(); | ||
|
||
const bloomPlayerHtml = "bloomplayer.htm"; | ||
export const Viewer: React.FunctionComponent<{ zipFilePath: string }> = ( | ||
props | ||
) => { | ||
const [htmPath, setHtmPath] = useState(""); | ||
useEffect(() => { | ||
console.log("bloom htmlpath=" + bloomPlayerHtml); | ||
const slashIndex = props.zipFilePath | ||
.replace(/\\/g, "/") | ||
|
||
.lastIndexOf("/"); | ||
|
||
const unpackedFolder = temp.mkdirSync("bloomPUB-viewer-"); | ||
const stream = fs.createReadStream(props.zipFilePath); | ||
// This will wait until we know the readable stream is actually valid before piping | ||
stream.on("open", () => { | ||
stream.pipe( | ||
unzipper | ||
.Extract({ path: unpackedFolder }) | ||
// unzipper calls this when it's done unzipping | ||
.on("close", () => { | ||
let filename = "index.htm"; | ||
if (!fs.existsSync(Path.join(unpackedFolder, filename))) { | ||
// it must be the old method, where we named the htm the same as the bloomd (which was obviously fragile): | ||
const bookTitle = props.zipFilePath.substring( | ||
slashIndex + 1, | ||
props.zipFilePath.length | ||
); | ||
filename = bookTitle | ||
.replace(/\.bloomd/gi, ".htm") | ||
.replace(/\.bloompub/gi, ".htm"); | ||
} | ||
setHtmPath((unpackedFolder + "\\" + filename).replace(/\\/g, "/")); | ||
}) | ||
); | ||
}); | ||
}, [props.zipFilePath]); | ||
|
||
console.log("htmPath = " + htmPath); | ||
return ( | ||
<div className="App"> | ||
{htmPath && ( | ||
<iframe | ||
style={{ width: "100%", height: "100%" }} | ||
src={`${bloomPlayerHtml}?allowToggleAppBar=true&url=file:///${htmPath}`} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; ////https://s3.amazonaws.com/bloomharvest/benjamin%40aconnectedplanet.org%2f130b6829-5367-4e5c-80d7-ec588aae5281/bloomdigital%2findex.htm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.