Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't build non-existent image URLs #894

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading