JellyfinAPI authHeader trim issue clear
This commit is contained in:
parent
3b7778b3cf
commit
0424436114
|
@ -43,6 +43,7 @@
|
|||
53FF7F2A263CF3F500585C35 /* LatestMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FF7F29263CF3F500585C35 /* LatestMediaView.swift */; };
|
||||
6213388E265F777C00A81A2A /* LibraryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6213388D265F777C00A81A2A /* LibraryViewModel.swift */; };
|
||||
62133890265F83A900A81A2A /* LibraryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6213388F265F83A900A81A2A /* LibraryListView.swift */; };
|
||||
621338932660107500A81A2A /* String++.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338922660107500A81A2A /* String++.swift */; };
|
||||
6273DD43265F4195009C1D0B /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD42265F4195009C1D0B /* Moya */; };
|
||||
6273DD45265F4195009C1D0B /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD44265F4195009C1D0B /* CombineMoya */; };
|
||||
6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */; };
|
||||
|
@ -108,6 +109,7 @@
|
|||
53FF7F29263CF3F500585C35 /* LatestMediaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatestMediaView.swift; sourceTree = "<group>"; };
|
||||
6213388D265F777C00A81A2A /* LibraryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryViewModel.swift; sourceTree = "<group>"; };
|
||||
6213388F265F83A900A81A2A /* LibraryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListView.swift; sourceTree = "<group>"; };
|
||||
621338922660107500A81A2A /* String++.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String++.swift"; sourceTree = "<group>"; };
|
||||
6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPI.swift; sourceTree = "<group>"; };
|
||||
6273DD4D265F47B2009C1D0B /* LibrarySearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySearchViewModel.swift; sourceTree = "<group>"; };
|
||||
AE8C3153265D60BF008AA076 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
|
||||
|
@ -156,6 +158,7 @@
|
|||
5377CBF3263B596A003A4E83 /* JellyfinPlayer */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
621338912660106C00A81A2A /* Extensions */,
|
||||
6273DD4A265F4794009C1D0B /* Domains */,
|
||||
6273DD46265F419B009C1D0B /* APIs */,
|
||||
AE8C3157265D6F5E008AA076 /* Resources */,
|
||||
|
@ -223,6 +226,14 @@
|
|||
path = ViewModels;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
621338912660106C00A81A2A /* Extensions */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
621338922660107500A81A2A /* String++.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6273DD46265F419B009C1D0B /* APIs */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -385,6 +396,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
621338932660107500A81A2A /* String++.swift in Sources */,
|
||||
53FF7F2A263CF3F500585C35 /* LatestMediaView.swift in Sources */,
|
||||
5377CBFE263B596B003A4E83 /* PersistenceController.swift in Sources */,
|
||||
5389276E263C25100035E14B /* ContinueWatchingView.swift in Sources */,
|
||||
|
|
|
@ -67,7 +67,7 @@ extension Filter {
|
|||
parameters["ImageTypeLimit"] = imageTypeLimit
|
||||
parameters["IncludeItemTypes"] = itemTypes.map(\.rawValue).joined(separator: ",")
|
||||
parameters["ParentId"] = parentID
|
||||
parameters["Recursive"] = recursive.description
|
||||
parameters["Recursive"] = recursive
|
||||
parameters["SortBy"] = sort?.rawValue
|
||||
parameters["SortOrder"] = asc?.rawValue
|
||||
parameters["Genres"] = genres.joined(separator: ",")
|
||||
|
@ -83,6 +83,7 @@ enum JellyfinAPI {
|
|||
}
|
||||
|
||||
extension JellyfinAPI: TargetType {
|
||||
|
||||
var baseURL: URL {
|
||||
switch self {
|
||||
case let .items(global, _, _),
|
||||
|
@ -117,12 +118,12 @@ extension JellyfinAPI: TargetType {
|
|||
parameters["searchTerm"] = searchQuery
|
||||
parameters["StartIndex"] = (page - 1) * 100
|
||||
parameters["Limit"] = 100
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.jellyfin)
|
||||
case let .items(_, filter, page):
|
||||
var parameters = filter.toParamters
|
||||
parameters["StartIndex"] = (page - 1) * 100
|
||||
parameters["Limit"] = 100
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.jellyfin)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,11 +131,18 @@ extension JellyfinAPI: TargetType {
|
|||
switch self {
|
||||
case let .items(global, _, _),
|
||||
let .search(global, _, _, _):
|
||||
return [
|
||||
"X-Emby-Authorization": global.authHeader,
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
]
|
||||
var headers = [String: String]()
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers["Accept"] = "application/json"
|
||||
headers["X-Emby-Authorization"] = global.authHeader
|
||||
return headers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension URLEncoding {
|
||||
|
||||
static var jellyfin: URLEncoding {
|
||||
URLEncoding(destination: .methodDependent, arrayEncoding: .noBrackets, boolEncoding: .literal)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,13 @@ struct ContentView: View {
|
|||
}
|
||||
|
||||
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String;
|
||||
globalData.authHeader = "MediaBrowser Client=\"SwiftFin\", Device=\"\(UIDevice.current.name)\", DeviceId=\"\(globalData.user?.device_uuid ?? "")\", Version=\"\(appVersion ?? "0.0.1")\", Token=\"\(globalData.authToken)\"";
|
||||
var header = "MediaBrowser "
|
||||
header.append("Client=\"SwiftFin\",")
|
||||
header.append("Device=\"\(UIDevice.current.name.removeRegexMatches(pattern: "[^\\w\\s]"))\",")
|
||||
header.append("DeviceId=\"\(globalData.user?.device_uuid ?? "")\",")
|
||||
header.append("Version=\"\(appVersion ?? "0.0.1")\",")
|
||||
header.append("Token=\"\(globalData.authToken)\"")
|
||||
globalData.authHeader = header
|
||||
|
||||
let request = RestRequest(method: .get, url: (globalData.server?.baseURI ?? "") + "/Users/Me")
|
||||
request.headerParameters["X-Emby-Authorization"] = globalData.authHeader
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// String++.swift
|
||||
// JellyfinPlayer
|
||||
//
|
||||
// Created by PangMo5 on 2021/05/28.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
func removeRegexMatches(pattern: String, replaceWith: String = "") -> String {
|
||||
do {
|
||||
let regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive)
|
||||
let range = NSRange(location: 0, length: count)
|
||||
return regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith)
|
||||
} catch { return self }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue