Add instance test to make sure thumbnails are reachable
This commit is contained in:
1 parent
46af79c2ae
commit
19de693298
3 files changed
+75
-3
No files matched your search
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- An instance test to make sure thumbnails are reachable
|
||||
|
||||
## [0.17.0] - 2023-11-17
|
||||
|
||||
### Added
|
||||
|
||||
+60
@@ -2,6 +2,7 @@ import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousInstanceTestingTask(input as object) as object
|
||||
@@ -29,6 +30,7 @@ function PrepareTests() as object
|
||||
content.AppendChild(CreateTestNode("Fetch video details", CanFetchVideoDetails))
|
||||
content.AppendChild(CreateTestNode("Fetch video comments", CanFetchVideoComments))
|
||||
content.AppendChild(CreateTestNode("Fetch video captions", CanFetchVideoCaptions))
|
||||
content.AppendChild(CreateTestNode("Fetch video thumbnails", CanFetchVideoThumbails))
|
||||
return content
|
||||
end function
|
||||
|
||||
@@ -251,3 +253,61 @@ function CanFetchVideoCaptions(instance as string, testNode as object) as void
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function CanFetchVideoThumbails(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
videoThumbnails = json.videoThumbnails
|
||||
if not IsArray(videoThumbnails) or videoThumbnails.Count() = 0
|
||||
testNode.state = "failed"
|
||||
testNode.details = `No thumbnails found in json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
contentNode = InvidiousContent.ToVideoContentNode(invalid, json, instance)
|
||||
thumbnail = contentNode.thumbnail
|
||||
if StringUtils.IsNullOrEmpty(thumbnail)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `No thumbnail found in json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
' Note: we could do a HEAD request, but Invidious returns 200 even for invalid thumbnails
|
||||
' To make sure we don't get a 200 for an invalid thumbnail, we do a GET request instead
|
||||
response = HttpClient.Get(thumbnail).NoCache().Await()
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = `${thumbnail} is not reachable\n${response.ErrorMessage(false)}`
|
||||
return
|
||||
end if
|
||||
|
||||
contentType = response.Headers()["Content-Type"]
|
||||
if StringUtils.IsNullOrEmpty(contentType) or not contentType.StartsWith("image/")
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid thumbnail data ${thumbnail} (Content-Type is not image/*)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video thumbnail for id "${videoId}" (${thumbnail})`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
@@ -185,7 +185,12 @@ namespace HttpClient
|
||||
|
||||
function ToCurlCommand() as string
|
||||
command = `curl "${m.BuildUrl()}"`
|
||||
command += ` \\\n -X ${m._method}`
|
||||
if m._method = "HEAD"
|
||||
command += ` \\\n -I`
|
||||
else if m._method <> "GET"
|
||||
command += ` \\\n -X ${m._method}`
|
||||
end if
|
||||
|
||||
command += ` \\\n --max-time ${m._timeoutSeconds}`
|
||||
command += ` \\\n --compressed`
|
||||
|
||||
@@ -573,7 +578,7 @@ namespace HttpClient
|
||||
return m._headers
|
||||
end function
|
||||
|
||||
function ErrorMessage() as string
|
||||
function ErrorMessage(includeBody = true as boolean) as string
|
||||
if m._errorMessage <> invalid
|
||||
return m._errorMessage
|
||||
end if
|
||||
@@ -588,7 +593,10 @@ namespace HttpClient
|
||||
else if m.IsCancelled()
|
||||
m._errorMessage = "Request cancelled."
|
||||
else if type(m.event) = "roUrlEvent"
|
||||
m._errorMessage = `Reason :${m.event.GetFailureReason() }\nStatusCode: ${m.StatusCode()}\nRequestId: ${m.event.GetSourceIdentity()}\nBody: ${m.event.GetString()}`
|
||||
m._errorMessage = `Reason :${m.event.GetFailureReason() }\nStatusCode: ${m.StatusCode()}\nRequestId: ${m.event.GetSourceIdentity()}`
|
||||
if includeBody
|
||||
m._errorMessage += `\nBody: ${m.event.GetString()}`
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
|
||||
|
||||
Reference in new issue
Block a user