Get rid of optional chaining (Roku 11 feature)

This commit is contained in:
Brahim Hadriche committed 2023-10-29 11:38:36 -04:00
1 parent af1fa0b401
commit 6cf735e089
3 files changed
+35 -14

No files matched your search

@@ -105,14 +105,21 @@ function IsReachable(instance as string, testNode as object) as void
return return
end if end if
name = json.software?.name software = json.software
if not IsString(name) if software = invalid
testNode.state = "failed" testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read software.name)` testNode.details = `Invalid json from ${url} (couldn't read $.software)`
return return
end if end if
version = json.software?.version name = software.name
if not IsString(name)
testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read $.software.name)`
return
end if
version = software.version
if not IsString(version) if not IsString(version)
testNode.state = "failed" testNode.state = "failed"
testNode.details = `Invalid json from ${url} (couldn't read software.version)` testNode.details = `Invalid json from ${url} (couldn't read software.version)`
@@ -185,8 +185,8 @@ function OnVideoPlayerStateChange() as void
end if end if
if state = "finished" if state = "finished"
metadata = content?.metadata metadata = content.metadata
if not PlayNext(metadata?.recommendedVideos) if metadata <> invalid and not PlayNext(metadata.recommendedVideos)
m.container@.watchedVideosClear(invalid) m.container@.watchedVideosClear(invalid)
VideoUtils.CloseVideo() VideoUtils.CloseVideo()
end if end if
@@ -231,7 +231,10 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
end if end if
for each metadata in recommendedVideos for each metadata in recommendedVideos
videoId = metadata?.videoId if metadata = invalid
continue for
end if
videoId = metadata.videoId
if videoId = invalid if videoId = invalid
continue for continue for
end if end if
@@ -53,26 +53,37 @@ namespace Http
response = context.response response = context.response
invidiousNode = context.server.task.invidious invidiousNode = context.server.task.invidious
feedSource = request.query["feed-source"]
if feedSource = invalid
response.Default(400, "Expected feed-source")
return true
end if
token = invidiousNode.authToken token = invidiousNode.authToken
if token = invalid if token = invalid
response.Default(403, "No token, not logged in") response.Default(403, "No token, not logged in")
return true return true
end if end if
feedSource = request.query["feed-source"]
if feedSource = invalid
response.Default(400, "Expected feed-source")
return true
end if
feedSource = ParseJson(feedSource) feedSource = ParseJson(feedSource)
if feedSource = invalid
response.Default(400, "Expected valid JSON for feed-source")
return true
end if
invService = new Invidious.InvidiousService(invidiousNode) invService = new Invidious.InvidiousService(invidiousNode)
invResponse = invService.MakeRequest(feedSource, feedSource.state?.queryParams)
additionalQueryParams = invalid
if feedSource.state <> invalid and feedSource.state.queryParams <> invalid
additionalQueryParams = feedSource.state.queryParams
end if
invResponse = invService.MakeRequest(feedSource, additionalQueryParams)
if not invResponse.success if not invResponse.success
response.Default(500, `Failed to make request: ${invResponse.error}`) response.Default(500, `Failed to make request: ${invResponse.error}`)
return true return true
end if end if
response.Json(invResponse.result) response.Json(invResponse.result)
return true return true
end function) end function)