Commit 1fa142a2 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: zip index data on import and export

Use JSzip to compress data exported to reduce size of downloaded/uploaded file
parent 5e3869bc
......@@ -7,6 +7,7 @@
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="flexsearch.js" type="text/javascript"></script>
<script src="jszip.min.js" type="text/javascript"></script>
<script src="action_mynij_search_import_export_index.js" type="text/javascript"></script>
</head>
<body>
......
(function (window, rJS, RSVP, jIO, File, Blob, document) {
(function (window, rJS, RSVP, jIO, File, Blob, document, JSZip) {
"use strict";
rJS(window)
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
......@@ -109,7 +109,8 @@
file_dict,
file_blob,
link,
url;
url,
zip_file;
file_dict = {
name: index_name,
......@@ -120,8 +121,16 @@
page: result
};
file_blob = new Blob([JSON.stringify(file_dict)], {type : "application/json"});
return gadget.downloadBlob(index_id + ".mynij", file_blob);
zip_file = new JSZip();
zip_file.file(index_id + ".json", JSON.stringify(file_dict));
zip_file.generateAsync({
type : "blob",
compression: "DEFLATE",
compressionOptions: {level: 9}
})
.then(function (ziped) {
return gadget.downloadBlob(index_id + ".zip", ziped);
});
});
})
......@@ -149,19 +158,24 @@
.push(function () {
return jIO.util.dataURItoBlob(dataurl);
})
.push(function (file_blob) {
return jIO.util.readBlobAsText(file_blob, "application/json");
})
.push(function (evt) {
index_dict = JSON.parse(evt.target.result);
doc.title = index_dict.name;
doc.links = index_dict.links;
doc.status = "built";
index_id = "index-" + doc.title;
return gadget.state.model_gadget.pushIndexBlob(
index_id,
index_dict,
{});
.push(function (data) {
var zip = new JSZip();
return zip.loadAsync(data)
.then(function(data){
return zip.file(Object.keys(data.files)[0]).async("string");
})
.then(function(data){
index_dict = JSON.parse(data);
//console.log(data);
doc.title = index_dict.name;
doc.links = index_dict.links;
doc.status = "built";
index_id = "index-" + doc.title;
return gadget.state.model_gadget.pushIndexBlob(
index_id,
index_dict,
{});
});
})
.push(function () {
return gadget.putIndexPage(index_dict.page);
......@@ -334,4 +348,4 @@
});
});
}(window, rJS, RSVP, jIO, File, Blob, document));
\ No newline at end of file
}(window, rJS, RSVP, jIO, File, Blob, document, JSZip));
\ No newline at end of file
......@@ -9,4 +9,5 @@ web_page_module/mynij_**
web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js
web_site_module/mynij_search
web_site_module/mynij_search/**
\ No newline at end of file
web_site_module/mynij_search/**
web_page_module/jszip_min_js
\ No newline at end of file
......@@ -9,4 +9,5 @@ web_page_module/mynij_**
web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js
web_site_module/mynij_search
web_site_module/mynij_search/**
\ No newline at end of file
web_site_module/mynij_search/**
web_page_module/jszip_min_js
\ No newline at end of file
......@@ -4,6 +4,7 @@ web_page_module/gadget_erp5_mynij_**
web_page_module/gadget_erp5_page_mynij_**
web_page_module/gadget_mynij_**
web_page_module/gadget_officejs_mynij_**
web_page_module/jszip_min_js
web_page_module/mynij-**
web_page_module/mynij_**
web_page_module/rss-parser.min.js.map
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment