Skip to content

Commit

Permalink
fix(publish): index.html: use contentLength instead of totalByteLength
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Mar 19, 2019
1 parent 5e052b5 commit 201e5da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
6 changes: 1 addition & 5 deletions publish/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@


window.onload = function () {

var totalWDBByteLength = $totalWDBByteLength;
var totalByteLength = totalWDBByteLength;

if (
AssetTool.isSupportStreamLoad()
) {
Expand All @@ -187,7 +183,7 @@
function (totalLoadedByteLength, contentLength, wdbPath) {
AssetTool.showOrCreateLoadingInfo(
totalLoadedByteLength,
totalByteLength
contentLength
);
},
function (state, gameObject) {
Expand Down
5 changes: 1 addition & 4 deletions publish/index_worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ <h1 id="detect" style="display: none">your browser not support sharedArrayBuffer
}


var totalWDBByteLength = $totalWDBByteLength;
var totalByteLength = totalWDBByteLength;

if (
AssetTool.isSupportStreamLoad()
) {
Expand All @@ -199,7 +196,7 @@ <h1 id="detect" style="display: none">your browser not support sharedArrayBuffer
function (totalLoadedByteLength, contentLength, wdbPath) {
AssetTool.showOrCreateLoadingInfo(
totalLoadedByteLength,
totalByteLength
contentLength
);
},
function (state, gameObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module LoadData = {
response
|> Fetch.Response.text
|> then_(jsStr => {
zip |. Zip.write("wd.js", `str(jsStr));
zip->(Zip.write("wd.js", `str(jsStr)));

useWorker ?
fetchFunc(. "./publish/wd.render.worker.js")
Expand All @@ -18,7 +18,7 @@ module LoadData = {
|> Fetch.Response.text
|> then_(jsStr => {
zip
|. Zip.write("wd.render.worker.js", `str(jsStr));
->(Zip.write("wd.render.worker.js", `str(jsStr)));

resolve(zip);
})
Expand All @@ -27,15 +27,6 @@ module LoadData = {
})
);

let _replaceIndexHtml = (indexHtmlStr, sceneGraphArrayBuffer) =>
indexHtmlStr
|> Js.String.replaceByRe(
[%re {|/\$totalWDBByteLength/img|}],
sceneGraphArrayBuffer
|> Js.Typed_array.ArrayBuffer.byteLength
|> Js.Int.toString,
);

let loadAndWriteIndexHtmlData =
(useWorker, sceneGraphArrayBuffer, fetchFunc, zip) =>
fetchFunc(.
Expand All @@ -45,12 +36,7 @@ module LoadData = {
response
|> Fetch.Response.text
|> then_(htmlStr =>
zip
|. Zip.write(
"index.html",
`str(_replaceIndexHtml(htmlStr, sceneGraphArrayBuffer)),
)
|> resolve
zip->(Zip.write("index.html", `str(htmlStr))) |> resolve
)
);

Expand All @@ -62,13 +48,15 @@ module LoadData = {
|> Fetch.Response.arrayBuffer
|> then_(arrayBuffer =>
zip
|. Zip.write(
~options=Options.makeWriteOptions(~binary=true, ()),
{j|res/loading/$name|j},
`trustme(
arrayBuffer |> TypeArrayType.newBlobFromArrayBuffer,
),
)
->(
Zip.write(
~options=Options.makeWriteOptions(~binary=true, ()),
{j|res/loading/$name|j},
`trustme(
arrayBuffer |> TypeArrayType.newBlobFromArrayBuffer,
),
)
)
|> resolve
)
)
Expand Down Expand Up @@ -121,8 +109,7 @@ module LoadData = {
response
|> Fetch.Response.text
|> then_(str =>
zip
|. Zip.write({j|config/$targetFileNamePath|j}, `str(str))
zip->(Zip.write({j|config/$targetFileNamePath|j}, `str(str)))
|> resolve
)
)
Expand Down Expand Up @@ -300,15 +287,17 @@ module Publish = {
|> _loadData(useWorker, sceneGraphArrayBuffer, fetchFunc)
|> WonderBsMost.Most.tap(zip =>
zip
|. Zip.write(
~options=Options.makeWriteOptions(~binary=true, ()),
"Scene.wdb",
`trustme(
sceneGraphArrayBuffer
|> TypeArrayType.newBlobFromArrayBuffer,
),
)
|. Zip.generateAsyncBlob(Zip.makeAsyncBlobOptions())
->(
Zip.write(
~options=Options.makeWriteOptions(~binary=true, ()),
"Scene.wdb",
`trustme(
sceneGraphArrayBuffer
|> TypeArrayType.newBlobFromArrayBuffer,
),
)
)
->(Zip.generateAsyncBlob(Zip.makeAsyncBlobOptions()))
|> Js.Promise.then_(content =>
FileSaver.saveAs(content, zipName ++ ".zip")
|> Js.Promise.resolve
Expand Down

0 comments on commit 201e5da

Please sign in to comment.