82 lines
3 KiB
Swift
82 lines
3 KiB
Swift
//
|
|
// JellyfinImageRequest.swift
|
|
//
|
|
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
/// The rendition to ask the server for when downloading artwork.
|
|
///
|
|
/// The server resizes and re-encodes artwork on demand, so a caller should request the size it will
|
|
/// actually draw rather than the original. An empty request, `JellyfinImageRequest()`, asks for the
|
|
/// server's default rendition.
|
|
///
|
|
/// Passing ``tag`` lets the server and any intermediate cache key the response, so a changed poster
|
|
/// is not served stale.
|
|
///
|
|
/// ```swift
|
|
/// let poster = try await client.image(
|
|
/// itemID: item.id!,
|
|
/// type: .primary,
|
|
/// request: JellyfinImageRequest(tag: item.imageTags[.primary], fillWidth: 300, fillHeight: 450)
|
|
/// )
|
|
/// ```
|
|
package struct JellyfinImageRequest: Hashable, Sendable {
|
|
/// The image tag the item advertised, used for cache validation.
|
|
package var tag: String?
|
|
/// The encoding to transcode into; `nil` lets the server choose.
|
|
package var format: JellyfinImageFormat?
|
|
/// Scale down so the width does not exceed this many pixels.
|
|
package var maxWidth: Int32?
|
|
/// Scale down so the height does not exceed this many pixels.
|
|
package var maxHeight: Int32?
|
|
/// Scale to exactly this width in pixels.
|
|
package var width: Int32?
|
|
/// Scale to exactly this height in pixels.
|
|
package var height: Int32?
|
|
/// Scale and crop to fill exactly this width in pixels.
|
|
package var fillWidth: Int32?
|
|
/// Scale and crop to fill exactly this height in pixels.
|
|
package var fillHeight: Int32?
|
|
/// The lossy compression quality, from 0 to 100.
|
|
package var quality: Int32?
|
|
|
|
/// Creates a request for the server's default rendition.
|
|
///
|
|
/// Each parameter sets the property of the same name.
|
|
package init(
|
|
tag: String? = nil,
|
|
format: JellyfinImageFormat? = nil,
|
|
maxWidth: Int32? = nil,
|
|
maxHeight: Int32? = nil,
|
|
width: Int32? = nil,
|
|
height: Int32? = nil,
|
|
fillWidth: Int32? = nil,
|
|
fillHeight: Int32? = nil,
|
|
quality: Int32? = nil
|
|
) {
|
|
self.tag = tag
|
|
self.format = format
|
|
self.maxWidth = maxWidth
|
|
self.maxHeight = maxHeight
|
|
self.width = width
|
|
self.height = height
|
|
self.fillWidth = fillWidth
|
|
self.fillHeight = fillHeight
|
|
self.quality = quality
|
|
}
|
|
}
|