[perf] reduce number of rendezvous when reading invidious instance name
This commit is contained in:
1 parent
c70d00e156
commit
75e6848df8
8 files changed
+31
-22
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { getHost } from "./Host";
|
||||
|
||||
const DISABLE_CACHE = true;
|
||||
|
||||
export class InvidiousApi {
|
||||
public instance: string;
|
||||
static host = () => `http://${getHost()}`
|
||||
|
||||
public endpoints: any;
|
||||
public isLoggedIn: boolean = false;
|
||||
public userCountryCode: string = 'US';
|
||||
private instance: string;
|
||||
|
||||
responseHandlers: any;
|
||||
|
||||
@@ -23,6 +26,18 @@ export class InvidiousApi {
|
||||
}
|
||||
}
|
||||
|
||||
public setInstance(instance: string) {
|
||||
if (!instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (instance.startsWith("http://127.0.0.1:8888")) {
|
||||
instance = instance.replace("http://127.0.0.1:8888", InvidiousApi.host());
|
||||
}
|
||||
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public async searchSuggestions(query: string) {
|
||||
const url = `${this.instance}/api/v1/search/suggestions?q=${encodeURIComponent(query)}®ion=${this.userCountryCode}`;
|
||||
const response = await fetch(url);
|
||||
|
||||
Reference in new issue
Block a user