Skip to content

Commit 0a593a0

Browse files
committed
[refactor] #152 SwiftSoupProvider 로직 수정
1 parent 70b704f commit 0a593a0

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

Projects/CoreKit/Sources/Data/Client/SwiftSoupClient/SwiftSoupProvider.swift

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,34 @@ import SwiftSoup
1010

1111
final class SwiftSoupProvider {
1212
func parseOGTitle(_ url: URL) async throws -> String? {
13-
return try await withCheckedThrowingContinuation { continuation in
14-
do {
15-
try parseOGMeta(url: url, type: "og:title", continuation: continuation)
16-
} catch {
17-
continuation.resume(throwing: error)
18-
}
19-
}
13+
try await parseOGMeta(url: url, type: "og:title")
2014
}
2115

2216
func parseOGImageURL(_ url: URL) async throws -> String? {
23-
return try await withCheckedThrowingContinuation { continuation in
24-
do {
25-
try parseOGMeta(url: url, type: "og:image", continuation: continuation)
26-
} catch {
27-
continuation.resume(throwing: error)
28-
}
29-
}
17+
try await parseOGMeta(url: url, type: "og:image")
3018
}
3119

32-
func parseOGMeta(
33-
url: URL,
34-
type: String,
35-
continuation: CheckedContinuation<String?, Error>
36-
) throws {
20+
func parseOGMeta(url: URL, type: String) async throws -> String? {
3721
let html = try String(contentsOf: url)
3822
let document = try SwiftSoup.parse(html)
3923

4024
if let metaData = try document.select("meta[property=\(type)]").first()?.attr("content") {
41-
continuation.resume(returning: metaData)
25+
return metaData
4226
} else {
43-
Task {
44-
var request = URLRequest(url: url)
45-
request.setValue(
46-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
47-
forHTTPHeaderField: "User-Agent"
48-
)
49-
50-
let (data, _) = try await URLSession.shared.data(for: request)
51-
guard let html = String(data: data, encoding: .utf8) else {
52-
continuation.resume(returning: nil)
53-
return
54-
}
55-
let document = try SwiftSoup.parse(html)
56-
let metaData = try document.select("meta[property=\(type)]").first()?.attr("content")
57-
58-
continuation.resume(returning: metaData)
27+
var request = URLRequest(url: url)
28+
request.setValue(
29+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
30+
forHTTPHeaderField: "User-Agent"
31+
)
32+
33+
let (data, _) = try await URLSession.shared.data(for: request)
34+
guard let html = String(data: data, encoding: .utf8) else {
35+
return nil
5936
}
37+
let document = try SwiftSoup.parse(html)
38+
let metaData = try document.select("meta[property=\(type)]").first()?.attr("content")
39+
40+
return metaData
6041
}
6142
}
6243
}

0 commit comments

Comments
 (0)