fix: 🐛 add missing headers for fetching children
This commit is contained in:
parent
7642a90cd6
commit
68c99cb1fb
|
@ -1,6 +1,5 @@
|
|||
import { DateTime } from 'luxon'
|
||||
import { EventEmitter } from 'events'
|
||||
import { htmlDecode } from 'js-htmlencode'
|
||||
import { decode } from 'he'
|
||||
import * as html from 'node-html-parser'
|
||||
import {
|
||||
|
@ -116,16 +115,12 @@ export class Api extends EventEmitter {
|
|||
return parse.user(data)
|
||||
}
|
||||
|
||||
parseXsrfToken(htmltext: string): string {
|
||||
const doc = html.parse(decode(htmltext))
|
||||
return doc.querySelector('input[name="__RequestVerificationToken"]').getAttribute('value') || ''
|
||||
}
|
||||
|
||||
async getChildren(): Promise<Child[]> {
|
||||
if (this.isFake) return fakeResponse(fake.children())
|
||||
|
||||
const hemResponse = await this.fetch('hemPage', routes.hemPage, this.session)
|
||||
const xsrfToken = this.parseXsrfToken(await hemResponse.text())
|
||||
const doc = html.parse(decode(await hemResponse.text()))
|
||||
const xsrfToken = doc.querySelector('input[name="__RequestVerificationToken"]').getAttribute('value') || ''
|
||||
if (this.session) {
|
||||
this.session.headers = {
|
||||
...this.session.headers,
|
||||
|
|
22
run.js
22
run.js
|
@ -74,17 +74,21 @@ async function run() {
|
|||
// const schedule = await api.getSchedule(children[0], DateTime.local(), DateTime.local().plus({ week: 1 }))
|
||||
// console.log(schedule)
|
||||
|
||||
console.log('news')
|
||||
const news = await api.getNews(children[0])
|
||||
if (children.length > 0) {
|
||||
console.log('news')
|
||||
const news = await api.getNews(children[0])
|
||||
|
||||
console.log('news details')
|
||||
const newsItems = await Promise.all(
|
||||
news.map((newsItem) =>
|
||||
api.getNewsDetails(children[0], newsItem)
|
||||
.catch((err) => { console.error(newsItem.id, err) })
|
||||
console.log('news details')
|
||||
const newsItems = await Promise.all(
|
||||
news.map((newsItem) =>
|
||||
api.getNewsDetails(children[0], newsItem)
|
||||
.catch((err) => { console.error(newsItem.id, err) })
|
||||
)
|
||||
)
|
||||
)
|
||||
console.log(newsItems)
|
||||
console.log(newsItems)
|
||||
} else {
|
||||
console.log('No children found!')
|
||||
}
|
||||
|
||||
// console.log('menu')
|
||||
// const menu = await api.getMenu(children[0])
|
||||
|
|
Loading…
Reference in New Issue