Don't build non-existent image URLs (#894)

This commit is contained in:
Daniel Chick 2023-10-30 14:39:44 -05:00 committed by GitHub
parent b538af6631
commit 46563c74ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ extension BaseItemDto {
_ type: ImageType,
maxWidth: Int? = nil,
maxHeight: Int? = nil
) -> URL {
) -> URL? {
_imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: id ?? "")
}
@ -27,7 +27,7 @@ extension BaseItemDto {
_ type: ImageType,
maxWidth: CGFloat? = nil,
maxHeight: CGFloat? = nil
) -> URL {
) -> URL? {
_imageURL(type, maxWidth: Int(maxWidth), maxHeight: Int(maxHeight), itemID: id ?? "")
}
@ -52,11 +52,11 @@ extension BaseItemDto {
// MARK: Series Images
func seriesImageURL(_ type: ImageType, maxWidth: Int? = nil, maxHeight: Int? = nil) -> URL {
func seriesImageURL(_ type: ImageType, maxWidth: Int? = nil, maxHeight: Int? = nil) -> URL? {
_imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: seriesID ?? "")
}
func seriesImageURL(_ type: ImageType, maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> URL {
func seriesImageURL(_ type: ImageType, maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> URL? {
_imageURL(type, maxWidth: Int(maxWidth), maxHeight: Int(maxHeight), itemID: seriesID ?? "")
}
@ -80,11 +80,13 @@ extension BaseItemDto {
maxWidth: Int?,
maxHeight: Int?,
itemID: String
) -> URL {
) -> URL? {
// TODO: See if the scaling is actually right so that it isn't so big
let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!)
let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!)
let tag = imageTags?[type.rawValue]
guard let tag = getImageTag(for: type) else { return nil }
let client = Container.userSession.callAsFunction().client
let parameters = Paths.GetItemImageParameters(
@ -102,6 +104,17 @@ extension BaseItemDto {
return client.fullURL(with: request)
}
private func getImageTag(for type: ImageType) -> String? {
switch type {
case .backdrop:
return backdropImageTags?.first
case .screenshot:
return screenshotImageTags?.first
default:
return imageTags?[type.rawValue]
}
}
fileprivate func _imageSource(_ type: ImageType, maxWidth: Int?, maxHeight: Int?) -> ImageSource {
let url = _imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: id ?? "")
let blurHash = blurHash(type)