diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs index 3e0509f1..63e321ee 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs @@ -220,11 +220,9 @@ function Search(text as string) if IsString(value) and value.len() > 0 feedSource.queryParams[filter] = value else if IsArray(value) and value.Count() > 0 - ' TODO:P1 this is http client implementation details leaking - ' We need a declarative way to set array types feedSource.queryParams[filter] = { value: value, - __arrayType: HttpClient.QueryParamArrayType.CommaSeparated + arrayType: HttpClient.QueryParamArrayType.CommaSeparated } end if end for diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs index 34f9df9d..c8a546a6 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs @@ -98,11 +98,7 @@ namespace Invidious request = HttpClient.Get(url) request.QueryParams(m.DefaultQueryParams()) request.QueryParam("q", q) - ' 5 hours cache. Videos should expire in 6 hours, but since we don't - ' have the exact expiration time, we'll use 5 hours. Invidious currently - ' Does a fresh fetch if the cache is older than 10 minutes. - ' https://github.com/iv-org/invidious/blob/069e91d2a609b1df94bdfbb693335969b2a281d8/src/invidious/videos.cr#L349 - request.CacheSeconds(60 * 60 * 5) + request.CacheSeconds(60 * 60 * 24) request.Cancellation(cancellation) @@ -116,7 +112,11 @@ namespace Invidious request = HttpClient.Get(url) request.QueryParams(m.DefaultQueryParams()) - request.CacheSeconds(60 * 60 * 6)' 6 hours + ' 5 hours cache. Videos should expire in 6 hours, but since we don't + ' have the exact expiration time, we'll use 5 hours. Invidious currently + ' Does a fresh fetch if the cache is older than 10 minutes. + ' https://github.com/iv-org/invidious/blob/069e91d2a609b1df94bdfbb693335969b2a281d8/src/invidious/videos.cr#L349 + request.CacheSeconds(60 * 60 * 5) request.Cancellation(cancellation) return request.Await() @@ -232,12 +232,8 @@ namespace Invidious else request.QueryParam(queryParamKey, queryParam.default) end if - else if IsArray(queryParam.default) - if queryParam.arrayType = "repeat" - request.QueryParamArray(queryParamKey, queryParam.default, HttpClient.QueryParamArrayType.Repeated) - else if queryParam.arrayType = "comma-separated" - request.QueryParamArray(queryParamKey, queryParam.default, HttpClient.QueryParamArrayType.CommaSeparated) - end if + else if IsArray(queryParam.default) and queryParam.arrayType <> invalid + request.QueryParamArray(queryParamKey, queryParam.default, queryParam.arrayType) else request.QueryParam(queryParamKey, queryParam.default) end if diff --git a/playlet-lib/src/config/invidious_video_api.yaml b/playlet-lib/src/config/invidious_video_api.yaml index 680fdd09..78dbfff8 100644 --- a/playlet-lib/src/config/invidious_video_api.yaml +++ b/playlet-lib/src/config/invidious_video_api.yaml @@ -13,7 +13,7 @@ trending: default: GetUserCountryCode fields: type: [] - arrayType: "comma-separated" + arrayType: "CommaSeparated" default: - title - videoId @@ -33,7 +33,7 @@ popular: queryParams: fields: type: [] - arrayType: "comma-separated" + arrayType: "CommaSeparated" default: - title - videoId @@ -77,7 +77,7 @@ search: - playlist - channel - all - arrayType: comma-separated + arrayType: CommaSeparated default: - video - playlist @@ -94,7 +94,7 @@ search: - 360 - location - hdr - arrayType: comma-separated + arrayType: CommaSeparated region: type: "#ISO3166" default: GetUserCountryCode diff --git a/playlet-lib/src/source/services/HttpClient.bs b/playlet-lib/src/source/services/HttpClient.bs index 99300b60..7f004cca 100644 --- a/playlet-lib/src/source/services/HttpClient.bs +++ b/playlet-lib/src/source/services/HttpClient.bs @@ -8,8 +8,8 @@ import "pkg:/source/utils/Types.bs" namespace HttpClient enum QueryParamArrayType - CommaSeparated - Repeated + CommaSeparated = "CommaSeparated" + Repeated = "Repeated" end enum function Get(url as string) as HttpRequest @@ -95,7 +95,7 @@ namespace HttpClient m._queryParams[key] = { value: valueArray, - __arrayType: arrayType + arrayType: arrayType } return m @@ -423,7 +423,7 @@ namespace HttpClient if not IsString(value) if IsAssociativeArray(value) and IsArray(value.value) - if value.__arrayType = HttpClient.QueryParamArrayType.Repeated + if value.arrayType = HttpClient.QueryParamArrayType.Repeated valueArray = value.value for each item in valueArray itemString = item @@ -437,7 +437,7 @@ namespace HttpClient hasQueryParams = true end if end for - else if value.__arrayType = HttpClient.QueryParamArrayType.CommaSeparated + else if value.arrayType = HttpClient.QueryParamArrayType.CommaSeparated valueArray = value.value for i = 0 to valueArray.Count() - 1 itemString = valueArray[i] diff --git a/playlet-web/src/lib/Api/InvidiousApi.ts b/playlet-web/src/lib/Api/InvidiousApi.ts index eeea8ee3..797624d8 100644 --- a/playlet-web/src/lib/Api/InvidiousApi.ts +++ b/playlet-web/src/lib/Api/InvidiousApi.ts @@ -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)}®ion=${this.userCountryCode}`); - return await response.json(); + const url = `${this.instance}/api/v1/search/suggestions?q=${encodeURIComponent(query)}®ion=${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)}®ion=${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);