Сообщение от voraa
|
Мало информации.
Что возвращает метод #checkFileExist? Он синхронный?
А что вы возвращаете, когда #checkFileExist не срабатывает?
А что возвращаете, если if(back) ложно?
|
Да, он синхронный
#checkFileExist(url, http) {
http.open('HEAD', url, false);
http.send();
if (http.status === 200) return true;
else return false;
}
#А что возвращаете, если if(back) ложно?
я вот как раз над этим думаю. сделал сначала парсинг данных в подключаемые странички, теперь дописываю возврат полученных данных
this.#readHTMLFile(filesName, function (filesText) {
let virtualDocument = document.implementation.createHTMLDocument("Virtual Document");
virtualDocument.documentElement.innerHTML = filesText;
let l = virtualDocument.querySelectorAll(".block-container");
l.length > 0 ? l : (new API()).ShowError({message: 'Error: File is empty'})
//Запрос за данными
let pars_meth = (new Parsing(1)).parsing(action);
if (typeof pars_meth === 'object')
{
const API_STAND = new API('fgjfkgjkfjg');
return API_STAND.makeQuery(pars_meth.name, obj => {
pars_meth.name = pars_meth.name.replace(/\/api\//i, '');
// Используем Фейкер. ТОЛЬКО ДЛЯ ТЕСТА!!!
obj = (new Faker(pars_meth.name, 200)).getDataFaker();
if (obj.status === "error") {
(new API()).ShowError({message: obj.data.message})
return false;
}
Object.keys(obj.data).map(function(message, index) {
let h = '.'+pars_meth.name+'_'+message;
// console.log(h);
// Ищем классы, и заменяем данные
let current_el = l[0].querySelector('.'+pars_meth.name+'_'+message);
if (current_el !== null) {
if (pars_meth.parse === 'li' && (current_el.tagName === 'OL' || current_el.tagName === 'UL') ) {
let p = obj.data[message].split(/(\d+)/);
obj.data[message] = '';
p.forEach(function (t, i) {
if (i % 2 === 0 && i !== 0) {
obj.data[message] += "<li>" + t + "</li>";
}
})
}
current_el.innerHTML = obj.data[message]
}
});
// Перебираем полученные nodes и вставляем в родительский документ (основной)
let AddSection = document.getElementsByClassName('container')[0];
AddSection.innerHTML = '';
[].forEach.call(l, function(item) {
AddSection.appendChild(item);
});
return obj;
}, pars_meth.method);
}
});