NetSchoolApi
NetSchoolApi copied to clipboard
Ошибка при запросе отчёта
Авторизация проходит нормально и какие-то данные по классам и списки классов получаю, но следующий код выдаёт ошибку:
// node ocenHistory.js lastYear
// node ocenHistory.js lastYear startFrom 17
// node ocenHistory.js year 2065181 // 2023-2024
// node ocenHistory.js year 2065181 startFrom 17
for (let i = 0; i < classList.length; i++) { //classList.length
const {
yearName,
yearId,
list
} = classList[i];
console.log(yearId);
if(args[0] == 'lastYear' && yearList[0].id != yearId){
console.log('skeep');
continue;
}
if(args[0] == 'year' && args[1] != yearId){
console.log('skeep');
continue;
}
for (let j = 0; j < list.length; j++) {
if(args[2] == 'startFrom' && (j+1) < parseInt(args[3])){
console.log((j+1)+' '+parseInt(args[3])+' skeep');
continue;
}
const classId = list[j].id;
const className = list[j].name;
//console.log(className);
var yearDir = yearToDir(yearId, years[yearId]);
var klassdir = yearDir+'/'+className+' '+classId;
if (!fs.existsSync(klassdir)){
fs.mkdirSync(klassdir);
fs.chmodSync(klassdir, 0o777);
}
var ucheniki = list[j]['ucheniki'];
for (let k = 0; k < ucheniki.length; k++) {
/* if(args[2] == 'startFrom' && j == parseInt(args[3]) && k < parseInt(args[4])){
console.log(k+' '+parseInt(args[4])+' skeep');
continue;
} */
var uchenikFio = ucheniki[k]['title'];
var uchenikId = ucheniki[k]['value'];
console.log((j+1)+'/'+list.length +' '+ (k+1)+'/'+ucheniki.length +' '+ years[yearId]+' '+className+' '+uchenikFio);
await new Promise(resolve => setTimeout(resolve, 100+getRandomInt(750)));
do {
var studenttotalmarks = null;
try {
studenttotalmarks = await user.reportFile({
url: "v2/reports/studenttotalmarks/queue",
yearId,
filters: [
// Другие фильтры
{
filterId: "PCLID",
filterValue: ''+classId
},
{
filterId: "SEPTYPE",
filterValue: "1",
},
{
filterId: "SID",
filterValue: ''+uchenikId,
},
],
});
} catch (err) {
studenttotalmarks = null;
console.log(inspect(err, { showHidden: true }));
await new Promise(resolve => setTimeout(resolve, 5000));
}
} while (studenttotalmarks == null);
fs.writeFile(klassdir+'/'+uchenikFio+' '+uchenikId+'.html', studenttotalmarks, err => {
if (err) {
throw err;
}
console.log('HTML data is saved.');
});
}
}
}
Ошибка такая:
Error: Unknown error.
Error:
at /var/www/ocenki/data/node_modules/netschoolapi/dist/methods/reportFile/index.js:158:32
at Generator.next (<anonymous>)
at /var/www/ocenki/data/node_modules/netschoolapi/dist/methods/reportFile/index.js:8:71
at new Promise (<anonymous>)
at __awaiter (/var/www/ocenki/data/node_modules/netschoolapi/dist/methods/reportFile/index.js:4:12)
at WebSocket.<anonymous> (/var/www/ocenki/data/node_modules/netschoolapi/dist/methods/reportFile/index.js:130:49)
at Object.onceWrapper (node:events:633:26)
at WebSocket.emit (node:events:518:28)
at WebSocket.emitClose (/var/www/ocenki/data/node_modules/ws/lib/websocket.js:262:12)
at emitErrorAndClose (/var/www/ocenki/data/node_modules/ws/lib/websocket.js:1042:13) {
[stack]: [Getter/Setter],
[message]: 'Unknown error.\nError: '
}
Нашёл решение, нужно в \netschoolapi\dist\methods\reportFile\index.js
заменить const ws = client.ws("queueHub", { params: { at } }); на const ws = client.ws("signalr/queueHub", { params: { at } });
исправлено в версии https://github.com/lentryd/NetSchoolApi/releases/tag/1.12.2