Small refactors to http client and caching

This commit is contained in:
Brahim Hadriche committed 2023-11-19 19:05:46 -05:00
1 parent 61327401b0
commit 9ae8601a32
5 files changed
+22 -27

No files matched your search

+4 -3
View File
@@ -23,11 +23,12 @@ export class InvidiousApi {
}
public async searchSuggestions(query: string) {
const response = await fetch(`${this.instance}/api/v1/search/suggestions?q=${encodeURIComponent(query)}&region=${this.userCountryCode}`);
return await response.json();
const url = `${this.instance}/api/v1/search/suggestions?q=${encodeURIComponent(query)}&region=${this.userCountryCode}`;
return await this.cachedFetch(url, 60 * 60 * 24);
}
public async search(query: string, filters: any, page: number = 1) {
// TODO:P2 use a FeedSource similar to brightscript version
let url = `${this.instance}/api/v1/search?q=${encodeURIComponent(query)}&region=${this.userCountryCode}`;
for (let filter in filters) {
if (typeof filters[filter] === 'string') {
@@ -93,6 +94,7 @@ export class InvidiousApi {
return !!(this.instance && this.endpoints && Object.keys(this.endpoints).length);
}
// TODO:P1 handle QueryParamArrayType (CommaSeparated/Repeated)
public async makeRequest(feedSource: any) {
if (!feedSource || !this.instance || !this.endpoints) {
return null;
@@ -237,7 +239,6 @@ export class InvidiousApi {
}
}
try {
tryCount -= 1;
const response = await fetch(url);