Skip to content

Commit

Permalink
Don't build non-existent image URLs (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
chickdan authored Oct 30, 2023
1 parent b538af6 commit 46563c7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ extension BaseItemDto {
_ type: ImageType,
maxWidth: Int? = nil,
maxHeight: Int? = nil
) -> URL {
) -> URL? {
_imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: id ?? "")
}

func imageURL(
_ type: ImageType,
maxWidth: CGFloat? = nil,
maxHeight: CGFloat? = nil
) -> URL {
) -> URL? {
_imageURL(type, maxWidth: Int(maxWidth), maxHeight: Int(maxHeight), itemID: id ?? "")
}

Expand All @@ -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 ?? "")
}

Expand All @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 46563c7

Please sign in to comment.