From d9706b08eb8699b70f5b0846a7a2a263406d0806 Mon Sep 17 00:00:00 2001 From: makinosp Date: Fri, 6 Sep 2024 21:18:39 +0900 Subject: [PATCH 1/8] fix: replacing image url --- Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift b/Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift index 12e8c48..d7d9c23 100644 --- a/Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift +++ b/Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift @@ -13,9 +13,9 @@ public protocol ImageUrlRepresentable { public extension ImageUrlRepresentable { func replaceImageUrl(url: URL, resolution: ImageResolution) -> URL? { - guard resolution != .origin, Int(url.lastPathComponent) != nil else { return url } + guard resolution != .origin, let number = Int(url.lastPathComponent), number > 1 else { return url } var urlString = url.absoluteString - if let range = urlString.range(of: url.lastPathComponent, options: .backwards) { + if let range = urlString.range(of: number.description, options: .backwards) { urlString.replaceSubrange(range, with: resolution.description) } return URL(string: urlString) From b141cfb9175ac1e27de7904f00c0257a363fef15 Mon Sep 17 00:00:00 2001 From: makinosp Date: Fri, 6 Sep 2024 21:57:22 +0900 Subject: [PATCH 2/8] refact: declare url constant --- Sources/VRCKit/APIClient.swift | 5 ++--- Sources/VRCKit/Utils/Const.swift | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 Sources/VRCKit/Utils/Const.swift diff --git a/Sources/VRCKit/APIClient.swift b/Sources/VRCKit/APIClient.swift index 14c2a5a..03074b2 100644 --- a/Sources/VRCKit/APIClient.swift +++ b/Sources/VRCKit/APIClient.swift @@ -25,9 +25,8 @@ public final class APIClient { /// Initializes the API client with optional username and password. public init() { - let domainUrl = "https://api.vrchat.cloud" - baseUrl = "\(domainUrl)/api/1" - cookieManager = CookieManager(domainURL: domainUrl) + baseUrl = "\(Const.apiBaseUrl)/\(Const.apiVersion)" + cookieManager = CookieManager(domainURL: Const.apiBaseUrl) } /// Set username and password. diff --git a/Sources/VRCKit/Utils/Const.swift b/Sources/VRCKit/Utils/Const.swift new file mode 100644 index 0000000..c529523 --- /dev/null +++ b/Sources/VRCKit/Utils/Const.swift @@ -0,0 +1,12 @@ +// +// Const.swift +// VRCKit +// +// Created by makinosp on 2024/09/06. +// + +public enum Const { + static let homeBaseUrl = "https://vrchat.com/home" + static let apiBaseUrl = "https://api.vrchat.cloud/api" + static let apiVersion = 1 +} From f2d96f2c170b7e35c900797549235d2ee321c122 Mon Sep 17 00:00:00 2001 From: makinosp Date: Fri, 6 Sep 2024 21:59:44 +0900 Subject: [PATCH 3/8] feat: add user url property --- Sources/VRCKit/Models/UserModel.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/VRCKit/Models/UserModel.swift b/Sources/VRCKit/Models/UserModel.swift index e686665..c2a5f57 100644 --- a/Sources/VRCKit/Models/UserModel.swift +++ b/Sources/VRCKit/Models/UserModel.swift @@ -44,6 +44,9 @@ public extension User { var platform: UserPlatform { presence.platform } + var url: URL? { + URL(string: [Const.homeBaseUrl, "user", id].joined(separator: "/")) + } } public extension User { From 6456f7b1deccf170b21afe8f342d608c96768ee0 Mon Sep 17 00:00:00 2001 From: makinosp Date: Fri, 6 Sep 2024 22:01:34 +0900 Subject: [PATCH 4/8] feat: add user url property of UserDetail --- Sources/VRCKit/Models/UserDetailModel.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/VRCKit/Models/UserDetailModel.swift b/Sources/VRCKit/Models/UserDetailModel.swift index 8a95c8c..690b00f 100644 --- a/Sources/VRCKit/Models/UserDetailModel.swift +++ b/Sources/VRCKit/Models/UserDetailModel.swift @@ -30,3 +30,9 @@ public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable { public let lastActivity: Date public let platform: UserPlatform } + +public extension UserDetail { + var url: URL? { + URL(string: [Const.homeBaseUrl, "user", id].joined(separator: "/")) + } +} From a736c09625cdb7785baf1230cfe9d036b8a4db4e Mon Sep 17 00:00:00 2001 From: makinosp Date: Sat, 7 Sep 2024 17:26:20 +0900 Subject: [PATCH 5/8] feat: implement presentation platform of instance --- Sources/VRCKit/Models/InstanceModel.swift | 8 ++++++++ Sources/VRCKit/Models/UserPlatformModel.swift | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Sources/VRCKit/Models/InstanceModel.swift b/Sources/VRCKit/Models/InstanceModel.swift index bc78498..63d8feb 100644 --- a/Sources/VRCKit/Models/InstanceModel.swift +++ b/Sources/VRCKit/Models/InstanceModel.swift @@ -64,6 +64,14 @@ public extension Instance { } return instanceTypeAlias.description } + + public var userPlatforms: [UserPlatform] { + [ + platforms.android > 0 ? .android : nil, + platforms.ios > 0 ? .ios : nil, + platforms.standalonewindows > 0 ? .standalonewindows : nil + ].compactMap(\.self) + } } extension Instance.GroupAccessType { diff --git a/Sources/VRCKit/Models/UserPlatformModel.swift b/Sources/VRCKit/Models/UserPlatformModel.swift index 2bb017d..708ef64 100644 --- a/Sources/VRCKit/Models/UserPlatformModel.swift +++ b/Sources/VRCKit/Models/UserPlatformModel.swift @@ -9,3 +9,19 @@ public enum UserPlatform: String, Codable { case android, ios, standalonewindows, web case blank = "" } + +extension UserPlatform: Identifiable { + public var id: String { self.rawValue } +} + +extension UserPlatform: CustomStringConvertible { + public var description: String { + switch self { + case .android: "Android" + case .ios: "iOS" + case .standalonewindows: "PC" + case .web: "Web" + case .blank: "" + } + } +} From aacae9bdb61c0ab1f5bb7abaa775e0547c53b6d3 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sat, 7 Sep 2024 17:29:57 +0900 Subject: [PATCH 6/8] fix: wrong access control --- Sources/VRCKit/Models/InstanceModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/VRCKit/Models/InstanceModel.swift b/Sources/VRCKit/Models/InstanceModel.swift index 63d8feb..805a191 100644 --- a/Sources/VRCKit/Models/InstanceModel.swift +++ b/Sources/VRCKit/Models/InstanceModel.swift @@ -65,7 +65,7 @@ public extension Instance { return instanceTypeAlias.description } - public var userPlatforms: [UserPlatform] { + var userPlatforms: [UserPlatform] { [ platforms.android > 0 ? .android : nil, platforms.ios > 0 ? .ios : nil, From 02e80b6a607dd31e59c42e18aca50604dde854bb Mon Sep 17 00:00:00 2001 From: makinosp Date: Sat, 7 Sep 2024 17:35:14 +0900 Subject: [PATCH 7/8] fix: type Any? --- Sources/VRCKit/Models/InstanceModel.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/VRCKit/Models/InstanceModel.swift b/Sources/VRCKit/Models/InstanceModel.swift index 805a191..f0f1274 100644 --- a/Sources/VRCKit/Models/InstanceModel.swift +++ b/Sources/VRCKit/Models/InstanceModel.swift @@ -67,9 +67,9 @@ public extension Instance { var userPlatforms: [UserPlatform] { [ - platforms.android > 0 ? .android : nil, - platforms.ios > 0 ? .ios : nil, - platforms.standalonewindows > 0 ? .standalonewindows : nil + platforms.android > 0 ? UserPlatform.android : nil, + platforms.ios > 0 ? UserPlatform.ios : nil, + platforms.standalonewindows > 0 ? UserPlatform.standalonewindows : nil ].compactMap(\.self) } } From d21827d8ecc2e8bb1009cd264269c417e245788f Mon Sep 17 00:00:00 2001 From: makinosp Date: Sat, 7 Sep 2024 17:36:59 +0900 Subject: [PATCH 8/8] fix: self path of compactMap --- Sources/VRCKit/Models/InstanceModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/VRCKit/Models/InstanceModel.swift b/Sources/VRCKit/Models/InstanceModel.swift index f0f1274..03462ca 100644 --- a/Sources/VRCKit/Models/InstanceModel.swift +++ b/Sources/VRCKit/Models/InstanceModel.swift @@ -70,7 +70,7 @@ public extension Instance { platforms.android > 0 ? UserPlatform.android : nil, platforms.ios > 0 ? UserPlatform.ios : nil, platforms.standalonewindows > 0 ? UserPlatform.standalonewindows : nil - ].compactMap(\.self) + ].compactMap { $0 } } }