fixed issues where search command always returned no results

This commit is contained in:
a. fox 2024-02-29 21:37:37 -05:00
parent ecdb1bdc35
commit b00669a167
3 changed files with 32 additions and 16 deletions

View File

@ -17,33 +17,31 @@ extension Seanut {
var query: String
static let columnWidth = 40
var queryItems: [(String, String)] {
[
("isRecursive", "true"),
("searchTerm", query.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!),
("fields", "Path,ChildCount".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!),
("includeItemTypes", "MusicAlbum,MusicArtist,Movie,Book,Playlist,Series,Audio".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
]
}
mutating func run() async {
Seanut.maybeSetLogger(options)
let config = Seanut.generateJellyfinConfiguration(url: options.domain.toURL()!,
token: Seanut.retrieveAccessToken(for: options.domain.toURL()!))
let config = Seanut.generateJellyfinConfiguration(
url: options.domain.toURL()!,
token: Seanut.retrieveAccessToken(for: options.domain.toURL()!)
)
let client = APIClient(baseURL: options.domain.toURL()!)
let searchRequest: Request<[Item]> = Seanut.jellyfinRequest(
result: [Item()],
let searchRequest: Request<SearchResult> = Seanut.jellyfinRequest(
result: SearchResult(),
config: config,
path: "/Items",
method: .get,
query: queryItems
query: [
("recursive", "true"),
("fields", "Path,ChildCount"),
("searchTerm", query),
("includeItemTypes", "MusicAlbum,MusicArtist,Movie,Book,Playlist,Series,Audio")
]
)
let response = try? await client.send(searchRequest).value
if let items = response {
if let items = response?.items {
print("Found \(items.count) results:")
let header = "ID".padding(toLength: SearchCommand.columnWidth, withPad: " ", startingAt: 0) +
"Type".padding(toLength: 15, withPad: " ", startingAt: 0) +

View File

@ -2,12 +2,30 @@
import Foundation
struct SearchResult: Codable {
let items: [Item]?
enum CodingKeys: String, CodingKey {
case items = "Items"
}
init() { self.items = nil }
}
struct Item: Codable {
let id: String?
let type: String?
let name: String?
let childCount: Int?
let path: String?
enum CodingKeys: String, CodingKey {
case id = "Id"
case type = "Type"
case name = "Name"
case childCount = "ChildCount"
case path = "Path"
}
init() {
self.id = nil

View File

@ -51,7 +51,7 @@ struct Seanut: AsyncParsableCommand {
path: String,
method: HTTPMethod,
body: Encodable? = nil,
query: [(String, String)]? = nil
query: [(String, String?)]? = nil
) -> Request<T> {
let id = String(path.split(separator: "/").last!)
return Request(