* refactor: switch ExternalAPI to Fetch API * fix: add missing auth token in Plex request * fix: send proper URL params * ci: try to fix format checker * ci: ci: try to fix format checker * ci: try to fix format checker * refactor: make tautulli use the ExternalAPI class * refactor: add rate limit to fetch api * refactor: add rate limit to fetch api * refactor: switch server from axios to fetch api * refactor: switch frontend from axios to fetch api * fix: switch from URL objects to strings * fix: use the right search params for ExternalAPI * fix: better log for ExternalAPI errors * feat: add retry to external API requests * fix: try to fix network errors with IPv6 * fix: imageProxy rate limit * revert: remove retry to external API requests * feat: set IPv4 first as an option * fix(jellyfinapi): add missing argument in JellyfinAPI constructor * refactor: clean the rate limit utility
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
interface JellyfinAuthenticationResult {
|
|
Id: string;
|
|
AccessToken: string;
|
|
ServerId: string;
|
|
}
|
|
|
|
class JellyAPI {
|
|
public login(
|
|
Hostname?: string,
|
|
Username?: string,
|
|
Password?: string
|
|
): Promise<JellyfinAuthenticationResult> {
|
|
return new Promise(
|
|
(
|
|
resolve: (result: JellyfinAuthenticationResult) => void,
|
|
reject: (e: Error) => void
|
|
) => {
|
|
fetch(Hostname + '/Users/AuthenticateByName', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Emby-Authorization':
|
|
'MediaBrowser Client="Jellyfin Web", Device="Firefox", DeviceId="TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NDsgcnY6ODUuMCkgR2Vja28vMjAxMDAxMDEgRmlyZWZveC84NS4wfDE2MTI5MjcyMDM5NzM1", Version="10.8.0"',
|
|
},
|
|
body: JSON.stringify({
|
|
Username: Username,
|
|
Pw: Password,
|
|
}),
|
|
})
|
|
.then((res) => {
|
|
if (!res.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
return res.json();
|
|
})
|
|
.then((data) => {
|
|
const response: JellyfinAuthenticationResult = {
|
|
Id: data.User.Id,
|
|
AccessToken: data.AccessToken,
|
|
ServerId: data.ServerId,
|
|
};
|
|
resolve(response);
|
|
})
|
|
.catch((error) => {
|
|
reject(error);
|
|
});
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
export default JellyAPI;
|