refactor: switch from Axios for Fetch API (#840)
* 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
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios';
|
||||
import Bowser from 'bowser';
|
||||
|
||||
interface PlexHeaders extends Record<string, string> {
|
||||
@@ -78,13 +77,14 @@ class PlexOAuth {
|
||||
'You must initialize the plex headers clientside to login'
|
||||
);
|
||||
}
|
||||
const response = await axios.post(
|
||||
'https://plex.tv/api/v2/pins?strong=true',
|
||||
undefined,
|
||||
{ headers: this.plexHeaders }
|
||||
);
|
||||
const res = await fetch('https://plex.tv/api/v2/pins?strong=true', {
|
||||
method: 'POST',
|
||||
headers: this.plexHeaders,
|
||||
});
|
||||
if (!res.ok) throw new Error();
|
||||
const data = await res.json();
|
||||
|
||||
this.pin = { id: response.data.id, code: response.data.code };
|
||||
this.pin = { id: data.id, code: data.code };
|
||||
|
||||
return this.pin;
|
||||
}
|
||||
@@ -136,16 +136,17 @@ class PlexOAuth {
|
||||
throw new Error('Unable to poll when pin is not initialized.');
|
||||
}
|
||||
|
||||
const response = await axios.get(
|
||||
`https://plex.tv/api/v2/pins/${this.pin.id}`,
|
||||
{ headers: this.plexHeaders }
|
||||
);
|
||||
const res = await fetch(`https://plex.tv/api/v2/pins/${this.pin.id}`, {
|
||||
headers: this.plexHeaders,
|
||||
});
|
||||
if (!res.ok) throw new Error();
|
||||
const data = await res.json();
|
||||
|
||||
if (response.data?.authToken) {
|
||||
this.authToken = response.data.authToken as string;
|
||||
if (data?.authToken) {
|
||||
this.authToken = data.authToken as string;
|
||||
this.closePopup();
|
||||
resolve(this.authToken);
|
||||
} else if (!response.data?.authToken && !this.popup?.closed) {
|
||||
} else if (!data?.authToken && !this.popup?.closed) {
|
||||
setTimeout(executePoll, 1000, resolve, reject);
|
||||
} else {
|
||||
reject(new Error('Popup closed without completing login'));
|
||||
|
||||
Reference in New Issue
Block a user