mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Load the token and cookie only once
This commit is contained in:
parent
5c90340165
commit
a738c3b211
1 changed files with 14 additions and 9 deletions
|
@ -2,12 +2,11 @@ const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
const { upperCase, method, head } = require('lodash')
|
const { upperCase } = require('lodash')
|
||||||
|
|
||||||
let X_CSRFTOKEN
|
let X_CSRFTOKEN
|
||||||
let COOKIE
|
let COOKIE
|
||||||
const cookiesToExtract = ['JSESSIONID', 'CSESSIONID', 'CSRFSESSION']
|
const cookiesToExtract = ['JSESSIONID', 'CSESSIONID', 'CSRFSESSION']
|
||||||
const extractedCookies = {}
|
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
@ -165,6 +164,11 @@ function parseItems(content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchCookieAndToken() {
|
async function fetchCookieAndToken() {
|
||||||
|
// Only fetch the cookies and csrfToken if they are not already set
|
||||||
|
if (X_CSRFTOKEN && COOKIE) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.request({
|
const response = await axios.request({
|
||||||
url: 'https://api.prod.sngtv.magentatv.de/EPG/JSON/Authenticate',
|
url: 'https://api.prod.sngtv.magentatv.de/EPG/JSON/Authenticate',
|
||||||
|
@ -215,11 +219,12 @@ async function fetchCookieAndToken() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setHeaders() {
|
function setHeaders() {
|
||||||
await fetchCookieAndToken()
|
return fetchCookieAndToken().then(() => {
|
||||||
return {
|
return {
|
||||||
X_CSRFTOKEN: X_CSRFTOKEN,
|
X_CSRFTOKEN: X_CSRFTOKEN,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Cookie: COOKIE
|
Cookie: COOKIE
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue