Compress save file (#986)

* Adding gzip compression for improving storage use and backward compatibility. (#984)

* Basic gzip an gunzip on load and save.

* refactor file save type to .gz and update the data in ui.

---------

Co-authored-by: Azgaar <maxganiev@yandex.com>

* refactor: cleanup, change wording

* feat: streamline saving options

* fix: fixes

---------

Co-authored-by: Efruz Yıldırır <30903352+yldrefruz@users.noreply.github.com>
This commit is contained in:
Azgaar 2023-08-15 16:50:28 +04:00 committed by GitHub
parent 5fba7d60f4
commit 26f48a48fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 197 additions and 104 deletions

30
main.js
View file

@ -270,7 +270,7 @@ async function checkLoadParameters() {
const url = new URL(window.location.href);
const params = url.searchParams;
// of there is a valid maplink, try to load .map file from URL
// of there is a valid maplink, try to load .gz/.map file from URL
if (params.get("maplink")) {
WARN && console.warn("Load map from URL");
const maplink = params.get("maplink");
@ -292,17 +292,20 @@ async function checkLoadParameters() {
}
// check if there is a map saved to indexedDB
try {
const blob = await ldb.get("lastMap");
if (blob) {
WARN && console.warn("Loading last stored map");
uploadMap(blob);
return;
if (byId("onloadBehavior").value === "lastSaved") {
try {
const blob = await ldb.get("lastMap");
if (blob) {
WARN && console.warn("Loading last stored map");
uploadMap(blob);
return;
}
} catch (error) {
ERROR && console.error(error);
}
} catch (error) {
console.error(error);
}
// else generate random map
WARN && console.warn("Generate random map");
generateMapOnLoad();
}
@ -574,9 +577,10 @@ void (function addDragToUpload() {
overlay.style.display = "none";
if (e.dataTransfer.items == null || e.dataTransfer.items.length !== 1) return; // no files or more than one
const file = e.dataTransfer.items[0].getAsFile();
if (file.name.indexOf(".map") == -1) {
// not a .map file
alertMessage.innerHTML = "Please upload a <b>.map</b> file you have previously downloaded";
if (!file.name.endsWith(".map") && !file.name.endsWith(".gz")) {
alertMessage.innerHTML =
"Please upload a map file (<i>.gz</i> or <i>.map</i> formats) you have previously downloaded";
$("#alert").dialog({
resizable: false,
title: "Invalid file format",
@ -596,7 +600,7 @@ void (function addDragToUpload() {
if (closeDialogs) closeDialogs();
uploadMap(file, () => {
overlay.style.display = "none";
overlay.innerHTML = "Drop a .map file to open";
overlay.innerHTML = "Drop a map file to open";
});
});
})();