Skip to content

Commit

Permalink
[fix] #152 RemindView에서 링크 이미지 조회 헤더에 User-Agent 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Oct 22, 2024
1 parent 7d0a86f commit b5d2523
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions Projects/Feature/FeatureRemind/Sources/Remind/RemindView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,15 @@ extension RemindView {
Button(action: { send(.컨텐츠_항목_눌렀을때(content: content)) }) {
recommendedContentCellLabel(content: content)
}

}

@ViewBuilder
private func recommendedContentCellLabel(content: BaseContentItem) -> some View {
ZStack(alignment: .bottom) {
LazyImage(url: .init(string: content.thumbNail)) { phase in
if let image = phase.image {
image
.resizable()
} else {
ZStack {
Color.pokit(.bg(.disable))

PokitSpinner()
.foregroundStyle(.pokit(.icon(.brand)))
.frame(width: 48, height: 48)
}
}
if let url = URL(string: content.thumbNail) {
recommendedContentCellImage(url: url)
} else {
imagePlaceholder
}

LinearGradient(
Expand Down Expand Up @@ -205,6 +195,34 @@ extension RemindView {
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
}

@MainActor
private func recommendedContentCellImage(url: URL) -> some View {
var request = URLRequest(url: url)
request.setValue(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
forHTTPHeaderField: "User-Agent"
)

return LazyImage(request: .init(urlRequest: request)) { phase in
if let image = phase.image {
image
.resizable()
} else {
imagePlaceholder
}
}
}

private var imagePlaceholder: some View {
ZStack {
Color.pokit(.bg(.disable))

PokitSpinner()
.foregroundStyle(.pink)
.frame(width: 48, height: 48)
}
}

@ViewBuilder
private func kebabButton(action: @escaping () -> Void) -> some View {
Button(action: action) {
Expand Down

0 comments on commit b5d2523

Please sign in to comment.