jellyfin-sdk-swift/Sources/Paths/GetItemImageAPI.swift
2024-05-20 12:37:34 -06:00

93 lines
3.4 KiB
Swift

//
// jellyfin-sdk-swift is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//
import Foundation
import Get
import URLQueryEncoder
public extension Paths {
/// Gets the item's image.
static func getItemImage(itemID: String, imageType: String, parameters: GetItemImageParameters? = nil) -> Request<Data> {
Request(path: "/Items/\(itemID)/Images/\(imageType)", method: "GET", query: parameters?.asQuery, id: "GetItemImage")
}
struct GetItemImageParameters {
public var maxWidth: Int?
public var maxHeight: Int?
public var width: Int?
public var height: Int?
public var quality: Int?
public var fillWidth: Int?
public var fillHeight: Int?
public var tag: String?
public var format: Format?
public var percentPlayed: Double?
public var unplayedCount: Int?
public var blur: Int?
public var backgroundColor: String?
public var foregroundLayer: String?
public var imageIndex: Int?
public typealias Format = JellyfinAPI.ImageFormat
public init(
maxWidth: Int? = nil,
maxHeight: Int? = nil,
width: Int? = nil,
height: Int? = nil,
quality: Int? = nil,
fillWidth: Int? = nil,
fillHeight: Int? = nil,
tag: String? = nil,
format: Format? = nil,
percentPlayed: Double? = nil,
unplayedCount: Int? = nil,
blur: Int? = nil,
backgroundColor: String? = nil,
foregroundLayer: String? = nil,
imageIndex: Int? = nil
) {
self.maxWidth = maxWidth
self.maxHeight = maxHeight
self.width = width
self.height = height
self.quality = quality
self.fillWidth = fillWidth
self.fillHeight = fillHeight
self.tag = tag
self.format = format
self.percentPlayed = percentPlayed
self.unplayedCount = unplayedCount
self.blur = blur
self.backgroundColor = backgroundColor
self.foregroundLayer = foregroundLayer
self.imageIndex = imageIndex
}
public var asQuery: [(String, String?)] {
let encoder = URLQueryEncoder()
encoder.encode(maxWidth, forKey: "maxWidth")
encoder.encode(maxHeight, forKey: "maxHeight")
encoder.encode(width, forKey: "width")
encoder.encode(height, forKey: "height")
encoder.encode(quality, forKey: "quality")
encoder.encode(fillWidth, forKey: "fillWidth")
encoder.encode(fillHeight, forKey: "fillHeight")
encoder.encode(tag, forKey: "tag")
encoder.encode(format, forKey: "format")
encoder.encode(percentPlayed, forKey: "percentPlayed")
encoder.encode(unplayedCount, forKey: "unplayedCount")
encoder.encode(blur, forKey: "blur")
encoder.encode(backgroundColor, forKey: "backgroundColor")
encoder.encode(foregroundLayer, forKey: "foregroundLayer")
encoder.encode(imageIndex, forKey: "imageIndex")
return encoder.items
}
}
}