Skip to content

Commit a3767bc

Browse files
committed
♻️ [refactor] 프로필 사진 filepath 유니크하게 개선
1 parent 9275383 commit a3767bc

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Fitfty/Projects/Profile/Sources/Profile/Views/ProfileView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010
import Common
11+
import Kingfisher
1112

1213
final class ProfileView: UIView {
1314

@@ -73,7 +74,7 @@ extension ProfileView {
7374
if refresh {
7475
imageView.kf.setImage(
7576
with: url,
76-
options: [.forceRefresh, .transition(.fade(0.3))]
77+
options: [.transition(.fade(0.5))]
7778
)
7879
} else {
7980
imageView.kf.setImage(with: url)

Fitfty/Projects/Setting/Sources/Profile/ViewController/ProfileSettingViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ private extension ProfileSettingViewController {
109109
self?.introductionTextField.text = text
110110

111111
case .updateProfileImage(let imageString):
112-
self?.profileImageView.kf.indicatorType = .activity
113112
if let url = URL(string: imageString ?? "") {
114113
self?.profileImageView.kf.setImage(
115114
with: url,
116-
options: [.forceRefresh]
115+
options: [.transition(.fade(0.5))]
117116
)
118117
}
119118

Fitfty/Projects/Setting/Sources/Profile/ViewModel/ProfileSettingViewModel.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public final class ProfileSettingViewModel: ViewModelType {
2525
public var state: AnyPublisher<ViewModelState, Never> { currentState.compactMap { $0 }.eraseToAnyPublisher() }
2626
private var currentState: CurrentValueSubject<ViewModelState?, Never> = .init(nil)
2727
private var currentImage: CurrentValueSubject<Data?, Never> = .init(nil)
28-
28+
private var profilePictureUrl: CurrentValueSubject<String?, Never> = .init(nil)
29+
2930
public init(repository: SettingRepository) {
3031
self.repository = repository
3132
}
@@ -34,9 +35,11 @@ public final class ProfileSettingViewModel: ViewModelType {
3435
Task {
3536
do {
3637
var url: String?
37-
if let imageData = currentImage.value {
38+
if let imageData = currentImage.value,
39+
let filename = filenameFromFilepath(profilePictureUrl.value) {
3840
let userToken = try await repository.getUserPrivacy().data?.userToken ?? UUID().uuidString
39-
url = try await AmplifyManager.shared.uploadImage(data: imageData, fileName: "profile/\(userToken)").absoluteString
41+
url = try await AmplifyManager.shared.uploadImage(data: imageData, fileName: "profile/\(userToken)_\(Date().currentfullDate)").absoluteString
42+
try await AmplifyManager.shared.delete(fileName: filename)
4043
}
4144
saveUserProfile(imageUrl: url, message: message)
4245
} catch {
@@ -53,7 +56,7 @@ public final class ProfileSettingViewModel: ViewModelType {
5356
Task {
5457
do {
5558
let response = try await repository.getUserProfile()
56-
59+
profilePictureUrl.send(response.data?.profilePictureUrl)
5760
currentState.send(.updateProfileMessage(response.data?.message))
5861
currentState.send(.updateProfileImage(response.data?.profilePictureUrl))
5962
} catch {
@@ -75,4 +78,16 @@ extension ProfileSettingViewModel {
7578
}
7679
}
7780
}
81+
82+
private func filenameFromFilepath(_ filepath: String?) -> String? {
83+
guard let filepath = filepath else {
84+
return nil
85+
}
86+
if filepath.contains("profile") {
87+
let splitProfile = filepath.components(separatedBy: "profile")
88+
return "profile" + splitProfile[1]
89+
} else {
90+
return nil
91+
}
92+
}
7893
}

0 commit comments

Comments
 (0)