Skip to content

Commit 74c76cf

Browse files
authored
Merge pull request #63 from makinosp:develop
feat: implement decoder / encoder for URL strings
2 parents 69a04e1 + 981a2e6 commit 74c76cf

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

.github/workflows/swift.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ name: Swift
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches:
9+
- "main"
10+
- "develop"
911
pull_request:
10-
branches: [ "main" ]
12+
branches:
13+
- "main"
14+
- "develop"
1115

1216
jobs:
1317
build:
14-
1518
runs-on: macos-latest
16-
1719
steps:
1820
- uses: actions/checkout@v4
1921
- name: Build
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// URLString.swift
3+
// VRCKit
4+
//
5+
// Created by makinosp on 2024/07/28.
6+
//
7+
8+
import Foundation
9+
10+
public struct URLString: Codable, Hashable {
11+
public let url: URL
12+
13+
public init(url: URL) {
14+
self.url = url
15+
}
16+
17+
public init(from decoder: any Decoder) throws {
18+
let container = try decoder.singleValueContainer()
19+
let urlString = try container.decode(String.self)
20+
guard let url = URL(string: urlString) else {
21+
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid URL string.")
22+
}
23+
self.url = url
24+
}
25+
26+
public func encode(to encoder: any Encoder) throws {
27+
var container = encoder.singleValueContainer()
28+
try container.encode(url.absoluteString)
29+
}
30+
}

Sources/VRCKit/Models/WorldModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public struct World: Codable, Identifiable, Hashable {
1717
public let capacity: Int
1818
public let tags: [String]
1919
public let releaseStatus: ReleaseStatus
20-
public let imageUrl: String
21-
public let thumbnailImageUrl: String
20+
public let imageUrl: URLString
21+
public let thumbnailImageUrl: URLString
2222
public let namespace: String?
2323
public let organization: String
2424
public let previewYoutubeId: String?

Sources/VRCKit/PreviewServices/PreviewDataProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ final class PreviewDataProvider {
206206
capacity: 32,
207207
tags: [],
208208
releaseStatus: .public,
209-
imageUrl: "https://ul.h3z.jp/ecWPM0Wk.jpg",
210-
thumbnailImageUrl: "https://ul.h3z.jp/ecWPM0Wk.jpg",
209+
imageUrl: URLString(url: URL(string: "https://ul.h3z.jp/ecWPM0Wk.jpg")!),
210+
thumbnailImageUrl: URLString(url: URL(string: "https://ul.h3z.jp/ecWPM0Wk.jpg")!),
211211
namespace: nil,
212212
organization: "",
213213
previewYoutubeId: "",

0 commit comments

Comments
 (0)