Skip to content

Commit

Permalink
New http client
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Aug 27, 2023
1 parent ca25037 commit f3a6dec
Show file tree
Hide file tree
Showing 18 changed files with 722 additions and 126 deletions.
5 changes: 1 addition & 4 deletions playlet-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"bslib": "npm:@rokucommunity/bslib@^0.1.1"
},
"ropm": {
"rootDir": "./src",
"noprefix": [
"roku-requests"
]
"rootDir": "./src"
},
"scripts": {
"prebuild": "rm -rf build/playlet-app",
Expand Down
13 changes: 1 addition & 12 deletions playlet-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions playlet-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
"description": "Unofficial Youtube client for Roku",
"dependencies": {
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
"log": "npm:roku-log@^0.9.3",
"roku-requests": "^1.2.0"
"log": "npm:roku-log@^0.9.3"
},
"ropm": {
"rootDir": "./src",
"noprefix": [
"roku-requests"
]
"rootDir": "./src"
},
"scripts": {
"prebuild": "rm -rf build/playlet-lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function HomeScreenRowContentTask(input as object) as boolean
service = new Invidious.InvidiousService(invidiousNode)
response = service.MakeRequest(contentNode.feed)

' TODO: handle cancellation
' TODO: handle unauthenticated requests
if response = invalid
contentNode.loadState = "failed"
Expand Down
34 changes: 31 additions & 3 deletions playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function OnTextChange() as void
end if

if m.searchSuggestionsTask <> invalid
m.searchSuggestionsTask.control = "stop"
m.searchSuggestionsTask.cancel = true
end if

m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
Expand All @@ -86,6 +86,18 @@ function OnTextChange() as void
end function

function OnSearchSuggestionsTaskResults(output as object) as void
if m.searchSuggestionsTask <> invalid and m.searchSuggestionsTask.id = output.task.id
m.searchSuggestionsTask = invalid
end if

if output.cancelled
return
end if

if not output.success
m.log.error(output.error)
return
end if
' In case this is an old request, discard suggestions
q = output.result.q
if q <> m.keyboard.text
Expand Down Expand Up @@ -137,7 +149,7 @@ end function

function Search(text as string)
if m.searchTask <> invalid
m.searchTask.control = "stop"
m.searchTask.cancel = "true"
end if

ShowLoadingScreen()
Expand All @@ -147,7 +159,23 @@ function Search(text as string)
}, OnSearchTaskResults)
end function

function OnSearchTaskResults(output as object)
function OnSearchTaskResults(output as object) as void
if m.searchTask <> invalid and m.searchTask.id = output.task.id
m.searchTask = invalid
end if

if output.cancelled
HideLoadingScreen()
return
end if

' TODO: Handle errors
if not output.success
m.log.error(output.error)
HideLoadingScreen()
return
end if

m.rowList.content = output.result.content
m.rowlist.focusable = true
NodeSetFocus(m.rowlist, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ function SearchSuggestionsTask(input as object) as object

service = new Invidious.InvidiousService(invidiousNode)

searchSuggestsions = q <> "" ? service.SearchSuggestions(q) : invalid
if m.top.cancel
return invalid
end if

searchSuggestsions = StringUtils.IsNullOrEmpty(q) ? invalid : service.SearchSuggestions(q, m.top.cancellation)

if m.top.cancel
return invalid
end if

history = SearchHistory.GetSaved(q)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function SearchTask(input as object) as object

service = new Invidious.InvidiousService(invidiousNode)

response = service.Search(q, { type: "video" }) 'video,playlist,channel
response = service.Search(q, { type: "video" }, m.top.cancellation) 'video,playlist,channel

instance = service.GetInstance()
rowContent = GetCategoryContent(contentNode, `Search - ${q}`, response, instance)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
import "pkg:/source/asyncTask/asyncTask.bs"
import "LatestLibVersionTask.bs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
import "pkg:/source/services/HttpClient.bs"

@asynctask
function LatestLibVersionTask() as object
Expand All @@ -9,15 +9,13 @@ function LatestLibVersionTask() as object
end function

function GetLatestPlayletLibVersionFromGithubReleases() as string
args = {
parseJson: false
}
response = Requests().request("HEAD", "https://github.com/iBicha/playlet/releases/latest", args)
response = HttpClient.Head("https://github.com/iBicha/playlet/releases/latest").Await()

if response.statusCode = 200
if response.headers.location <> invalid
if response.StatusCode() = 200
headers = response.Headers()
if headers.location <> invalid
regex = CreateObject("roRegex", "/v?(\d+\.\d+\.\d+)", "")
match = regex.match(response.headers.location)
match = regex.match(headers.location)
if match.Count() = 2
return match[1]
end if
Expand Down
Loading

0 comments on commit f3a6dec

Please sign in to comment.