Skip to content

Commit

Permalink
[skip-ci] small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Dec 26, 2024
1 parent 310d53d commit fa3921c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ 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

@get("/playlet-invidious-backend/api/v1/stats")
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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions playlet-web/src/lib/LinkDragDrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa3921c

Please sign in to comment.