Commit 933ebfd7 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: fix build index with broken sitemap/rss url

parent 2e87a198
......@@ -94,8 +94,16 @@
gadget.state.current_build = entry;
link_list = entry.links.split("\n").filter(l => l.length > 0);
return gadget.build_index(link_list, entry.index_name)
.push(function () {
console.log("done building index");
.push(function (build_failed) {
if (build_failed) {
failed = true;
status = 'build failed';
gadget.state.current_build = undefined;
return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built failed!",
status: "error"
});
}
return gadget.save_index(entry.index_name)
.push(function (result) {
status = 'built';
......@@ -191,11 +199,27 @@
.declareMethod("build_index", function (links, index_name) {
var gadget = this,
promise_list = [],
build_queue = new RSVP.Queue(),
failed = false,
i;
function build_link(link, name) {
return build_queue
.push(function () {
if (!failed)
return gadget.get_and_handle(link, name);
})
.push(undefined, function (error) {
console.log(error);
failed = true;
});
}
for (i = 0; i < links.length; i += 1) {
promise_list.push(gadget.get_and_handle(links[i], index_name));
build_link(links[i], index_name);
}
return RSVP.all(promise_list);
return build_queue
.push(function () {
return failed;
});
})
.declareMethod("get_and_handle", function (link, index_name) {
......@@ -222,9 +246,6 @@
link,
index_name);
}
})
.push(undefined, function (error) {
console.log(error);
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.2089.59132.27426</string> </value>
<value> <string>990.2403.64322.7168</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1613386502.59</float>
<float>1613405732.81</float>
<string>UTC</string>
</tuple>
</state>
......
(function (window, rJS, RSVP) {
"use strict";
function validateHttpUrl(value) {
/*jslint regexp: true*/
if (/\(?(?:(http|https):\/\/)(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[\dabcedf:]+\])(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/i.test(value)) {
return true;
}
/*jslint regexp: false*/
return false;
}
rJS(window)
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
......@@ -21,7 +31,29 @@
gadget = this,
list = parent_options.doc.links,
index_name = parent_options.doc.title,
jio_key = parent_options.action_options.jio_key;
jio_key = parent_options.action_options.jio_key,
link_list,
i;
return_submit_dict = {
notify: {
message: "",
status: "success"
},
redirect: {
command: "display",
options: {page : "ojs_local_controller", jio_key: jio_key}
}
};
link_list = list.split("\n").filter(l => l.length > 0);
for (i = 0; i < link_list.length; i += 1) {
if (!validateHttpUrl(link_list[i])) {
return_submit_dict.notify.message = "Links paramter has invalid URL(s)!";
return_submit_dict.notify.status = "error";
return return_submit_dict;
}
}
return gadget.getSetting("build_dict", {})
.push(function(build_dict){
......@@ -34,16 +66,8 @@
return gadget.setSetting("build_dict", build_dict);
})
.push(function(){
return_submit_dict = {
notify: {
message: "Index " + index_name + " will start building...",
status: "success"
},
redirect: {
command: "display",
options: {page : "ojs_local_controller", jio_key: jio_key}
}
};
return_submit_dict.notify.message = "Index " + index_name +
" will start building...";
return return_submit_dict;
});
});
......
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