Commit 87ed3225 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Stabilize charing index through torrent

Save downloaded torrent as zipped file to blob and reuse the file for next sharing. This is useful so Webtorrent will generate same infoHash and same magnet uri.
If index is built again, saved torrent blob file is removed (because data changed).
parent e6b9cc10
...@@ -113,9 +113,6 @@ ...@@ -113,9 +113,6 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return gadget.changeState({
service: options.service || true
});
}) })
.declareMethod("digestMessage", function digestMessage(text, algorithm) { .declareMethod("digestMessage", function digestMessage(text, algorithm) {
...@@ -281,6 +278,7 @@ ...@@ -281,6 +278,7 @@
zipped_blob, zipped_blob,
doc_blob, doc_blob,
index_name, index_name,
index_id,
doc, doc,
ext, ext,
i, i,
...@@ -311,7 +309,8 @@ ...@@ -311,7 +309,8 @@
} else if (type === 'map') { } else if (type === 'map') {
insert_blob(id, type, data); insert_blob(id, type, data);
} else if (type === 'ids') { } else if (type === 'ids') {
index_name = id.split("index-")[1] index_name = id.split("index-")[1];
index_id = id;
insert_blob(id, type, data); insert_blob(id, type, data);
} }
} }
...@@ -391,6 +390,16 @@ ...@@ -391,6 +390,16 @@
status: "success" status: "success"
}) })
}) })
.push(function () {
var zipped_file = new File([zipped_blob], name, {type: 'blob'});
// Save this blob for future seed
// this is done to try to keep same torrent magnet uri
return gadget.state.model_gadget.putAttachment(
index_id,
"zipped",
zipped_blob
);
})
.push(function () { .push(function () {
// stop seeding the torrent // stop seeding the torrent
gadget.state.client.destroy(function (err) { gadget.state.client.destroy(function (err) {
...@@ -416,7 +425,7 @@ ...@@ -416,7 +425,7 @@
element, element,
i, i,
key_list = []; key_list = [];
if (!container || !gadget.state.service) if (!container)
return; return;
info = container.querySelector('h2.info') info = container.querySelector('h2.info')
seed_element = container.querySelector('.torrent-seed'); seed_element = container.querySelector('.torrent-seed');
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>995.7322.44137.26811</string> </value> <value> <string>995.8389.48244.44663</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1632931116.23</float> <float>1632998940.56</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
counter = 0, counter = 0,
downloading, downloading,
magnet; magnet;
if (!index_dict.infohash || ! index_dict.namehash)
return;
return gadget.state.model_gadget.getRtcconfig() return gadget.state.model_gadget.getRtcconfig()
.push(function (rtcconfig) { .push(function (rtcconfig) {
magnet = "magnet:?xt=urn:btih:"; magnet = "magnet:?xt=urn:btih:";
if (!index_dict.infohash || ! index_dict.namehash)
return;
// XXX - hardcoded tracker uri // XXX - hardcoded tracker uri
magnet += index_dict.infohash + "&dn=" + index_dict.namehash + magnet += index_dict.infohash + "&dn=" + index_dict.namehash +
"&tr=wss://tracker.openwebtorrent.com&tr=" + "&tr=wss://tracker.openwebtorrent.com&tr=" +
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>995.7472.37563.34030</string> </value> <value> <string>995.7486.28357.59426</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1632938785.95</float> <float>1633001136.24</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -47,6 +47,11 @@ ...@@ -47,6 +47,11 @@
return storage.putAttachment.apply(storage, arguments); return storage.putAttachment.apply(storage, arguments);
}) })
.declareMethod('removeAttachment', function () {
var storage = this.state.db;
return storage.removeAttachment.apply(storage, arguments);
})
.declareMethod('put', function () { .declareMethod('put', function () {
var storage = this.state.db; var storage = this.state.db;
return storage.put.apply(storage, arguments); return storage.put.apply(storage, arguments);
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>995.5735.8910.39321</string> </value> <value> <string>995.7487.50566.25651</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1632938866.29</float> <float>1632999521.15</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
link_list = entry.links.split("\n").filter(l => l.length > 0); link_list = entry.links.split("\n").filter(l => l.length > 0);
return gadget.build_index(link_list, entry.index_name) return gadget.build_index(link_list, entry.index_name)
.push(function (build_failed) { .push(function (build_failed) {
var counter;
if (build_failed) { if (build_failed) {
failed = true; failed = true;
status = 'build failed'; status = 'build failed';
...@@ -112,10 +113,23 @@ ...@@ -112,10 +113,23 @@
} }
return gadget.save_index(entry.index_name) return gadget.save_index(entry.index_name)
.push(function (result) { .push(function (result) {
counter = result;
// If there is a blob attachment, remove it
return gadget.state.model_gadget
.removeAttachment("index-" + entry.index_name, "zipped")
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return;
}
console.error(error);
});
})
.push(function () {
status = 'built'; status = 'built';
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built : " + message: "Index '" + entry.index_name + "' built : " +
result + " item(s) added.", counter + " item(s) added.",
status: "success" status: "success"
}); });
}); });
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>994.62696.17158.27613</string> </value> <value> <string>995.8450.35012.5768</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1632420438.32</float> <float>1632999148.09</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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