mirror of
https://github.com/jellyfin/Swiftfin.git
synced 2024-12-13 17:16:00 +00:00
JellyfinAPI applied in Library, Search
This commit is contained in:
parent
3b38a20625
commit
7ada918ea5
@ -62,7 +62,7 @@ extension Filter {
|
||||
parameters["ImageTypeLimit"] = imageTypeLimit
|
||||
parameters["IncludeItemTypes"] = itemTypes.map(\.rawValue).joined(separator: ",")
|
||||
parameters["ParentId"] = parentID
|
||||
parameters["Recursive"] = recursive
|
||||
parameters["Recursive"] = recursive.description
|
||||
parameters["SortBy"] = sort?.rawValue
|
||||
parameters["SortOrder"] = asc?.rawValue
|
||||
parameters["Genres"] = genres.joined(separator: ",")
|
||||
@ -108,15 +108,15 @@ extension JellyfinAPI: TargetType {
|
||||
switch self {
|
||||
case let .search(_, filter, searchQuery, page):
|
||||
var parameters = filter.toParamters
|
||||
parameters["searchTerm"] = searchQuery.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
||||
parameters["StartIndex"] = page * 100
|
||||
parameters["searchTerm"] = searchQuery
|
||||
parameters["StartIndex"] = (page - 1) * 100
|
||||
parameters["Limit"] = 100
|
||||
return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
|
||||
case let .items(_, filter, page):
|
||||
var parameters = filter.toParamters
|
||||
parameters["StartIndex"] = page * 100
|
||||
parameters["StartIndex"] = (page - 1) * 100
|
||||
parameters["Limit"] = 100
|
||||
return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ extension JellyfinAPI: TargetType {
|
||||
case let .items(global, _, _),
|
||||
let .search(global, _, _, _):
|
||||
return [
|
||||
"X-Emby-Authorization": global.authHeader,
|
||||
"X-Emby-Authorization": global.authHeader
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,9 @@ final class LibraryViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
fileprivate func requestItems() {
|
||||
print(globalData.server?.baseURI)
|
||||
print(globalData.authHeader)
|
||||
print(filter)
|
||||
isLoading = true
|
||||
provider.requestPublisher(.items(globalData: globalData, filter: filter, page: page))
|
||||
// .map(ResumeItem.self) TO DO
|
||||
|
@ -42,6 +42,7 @@ final class LibrarySearchViewModel: ObservableObject {
|
||||
cancellables.removeAll()
|
||||
|
||||
$searchQuery
|
||||
.debounce(for: 0.25, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: requestSearch(query:))
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
@ -55,6 +56,7 @@ final class LibrarySearchViewModel: ObservableObject {
|
||||
self.isLoading = false
|
||||
}, receiveValue: { response in
|
||||
let body = response.data
|
||||
self.items.removeAll()
|
||||
do {
|
||||
let json = try JSON(data: body)
|
||||
for (_, item): (String, JSON) in json["Items"] {
|
||||
|
@ -92,14 +92,14 @@ struct LibraryView: View {
|
||||
.navigationTitle(title)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
if viewModel.isHiddenPreviousButton {
|
||||
if !viewModel.isHiddenPreviousButton {
|
||||
Button {
|
||||
viewModel.requestPreviousPage()
|
||||
} label: {
|
||||
Image(systemName: "chevron.left")
|
||||
}
|
||||
}
|
||||
if viewModel.isHiddenNextButton {
|
||||
if !viewModel.isHiddenNextButton {
|
||||
Button {
|
||||
viewModel.requestNextPage()
|
||||
} label: {
|
||||
|
Loading…
Reference in New Issue
Block a user