@ -1,4 +1,5 @@
let csrfToken : string
let csrfToken : string
let synoToken : string | undefined // required for synology API requests
let unraidCsrfToken : string | undefined // required for unraid POST requests (#8062)
let unraidCsrfToken : string | undefined // required for unraid POST requests (#8062)
// apiFetch wraps the standard JS fetch function with csrf header
// apiFetch wraps the standard JS fetch function with csrf header
@ -15,9 +16,13 @@ export function apiFetch(
) : Promise < Response > {
) : Promise < Response > {
const urlParams = new URLSearchParams ( window . location . search )
const urlParams = new URLSearchParams ( window . location . search )
const nextParams = new URLSearchParams ( params )
const nextParams = new URLSearchParams ( params )
const token = urlParams . get ( "SynoToken" )
if ( synoToken ) {
if ( token ) {
nextParams . set ( "SynoToken" , synoToken )
nextParams . set ( "SynoToken" , token )
} else {
const token = urlParams . get ( "SynoToken" )
if ( token ) {
nextParams . set ( "SynoToken" , token )
}
}
}
const search = nextParams . toString ( )
const search = nextParams . toString ( )
const url = ` api ${ endpoint } ${ search ? ` ? ${ search } ` : "" } `
const url = ` api ${ endpoint } ${ search ? ` ? ${ search } ` : "" } `
@ -62,6 +67,10 @@ function updateCsrfToken(r: Response) {
}
}
}
}
export function setSynoToken ( token? : string ) {
synoToken = token
}
export function setUnraidCsrfToken ( token? : string ) {
export function setUnraidCsrfToken ( token? : string ) {
unraidCsrfToken = token
unraidCsrfToken = token
}
}