[skip-ci] small refactor

This commit is contained in:
Brahim Hadriche committed 2024-12-26 17:49:26 -05:00
1 parent 310d53dd61
commit fa3921cd33
2 files changed
+47 -13

No files matched your search

@@ -12,8 +12,10 @@ namespace Http
function AuthorizeToken(context as object) as boolean
response = context.response
error = "Playlet built-in Invidious backend is not a real Invidious instance, and does not support accounts."
response.Default(400, error)
response.Json({
"error": "Playlet built-in Invidious backend is not a real Invidious instance, and does not support accounts."
})
response.http_code = 400
return true
end function
@@ -21,8 +23,10 @@ namespace Http
function GetStats(context as object) as boolean
response = context.response
error = "Playlet built-in Invidious backend is not a real Invidious instance, and does not support stats."
response.Default(400, error)
response.Json({
"error": "Playlet built-in Invidious backend is not a real Invidious instance, and does not support stats."
})
response.http_code = 400
return true
end function
@@ -33,7 +37,10 @@ namespace Http
feeds = InnertubeService.GetTrending({ type: request.query.type })
if not IsArray(feeds) or feeds.Count() = 0
response.Default(500, "Failed to get trending feed")
response.Json({
"error": "Failed to get trending feed"
})
response.http_code = 500
return true
end if
@@ -99,7 +106,10 @@ namespace Http
feeds = InnertubeService.Search(query, options)
if not IsArray(feeds) or feeds.Count() = 0
response.Default(500, "Failed to search")
response.Json({
"error": "Failed to search"
})
response.http_code = 500
return true
end if
@@ -114,20 +124,29 @@ namespace Http
url = request.query.url
if StringUtils.IsNullOrEmpty(url)
response.Default(400, "Missing 'url' query parameter")
response.Json({
"error": "Missing 'url' query parameter"
})
response.http_code = 400
return true
end if
json = InnertubeService.ResolveUrl(url, response)
if json = invalid
response.Default(500, "Failed to resolve URL")
response.Json({
"error": "Failed to resolve URL"
})
response.http_code = 500
return true
end if
endpoint = json["endpoint"]
pageType = ValidString(ObjectUtils.Dig(endpoint, ["commandMetadata", "webCommandMetadata", "webPageType"]))
if pageType = "WEB_PAGE_TYPE_UNKNOWN" or pageType = ""
response.Default(400, "Unknown url")
response.Json({
"error": "Unknown page type"
})
response.http_code = 400
return true
end if
@@ -198,7 +217,10 @@ namespace Http
playerResponse = InnertubeService.GetVideoMetadata(videoId)
if not playerResponse.IsSuccess()
response.Default(playerResponse.StatusCode(), playerResponse.ErrorMessage())
response.Json({
"error": playerResponse.ErrorMessage()
})
response.http_code = playerResponse.StatusCode()
return true
end if
@@ -221,7 +243,10 @@ namespace Http
playlist = InnertubeService.GetPlaylist(playlistId, options)
if playlist = invalid
response.Default(500, "Failed to get playlist")
response.Json({
"error": "Failed to get playlist"
})
response.http_code = 500
return true
end if
@@ -257,7 +282,10 @@ namespace Http
channelId = channelAndTab[0]
channel = InnertubeService.GetChannel(channelId, options)
if channel = invalid
response.Default(500, "Failed to get channel")
response.Json({
"error": "Failed to get channel"
})
response.http_code = 500
return true
end if
@@ -274,7 +302,10 @@ namespace Http
channel = InnertubeService.GetChannel(channelId, options)
if channel = invalid
response.Default(500, "Failed to get channel")
response.Json({
"error": "Failed to get channel"
})
response.http_code = 500
return true
end if
+3
View File
@@ -110,6 +110,9 @@
try {
isLoading = true;
videoMetadata = await PlayletApi.getVideoInfo(videoId);
if (videoMetadata?.error) {
throw videoMetadata.error;
}
videoStartAtChecked = timestamp !== undefined;
if (videoStartAtChecked) {
videoStartAtTimestamp = timestamp;