-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileRepository.swift
More file actions
48 lines (42 loc) · 1.52 KB
/
FileRepository.swift
File metadata and controls
48 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// FileRepository.swift
// DataSource
//
// Created by 이동현 on 11/22/25.
//
import Domain
import Foundation
final class FileRepository: FileRepositoryProtocol {
private let networkService = NetworkService.shared
func fetchPresignedURL(prefix: String?, fileNames: [String]) async throws -> [String : String]? {
let dtos = fileNames.map { FilePresignedConditionDTO(prefix: prefix, fileName: $0) }
let endpoint = FilePresignedEndpoint.fetchPresignedURL(presignedConditions: dtos)
do {
return try await networkService.request(endpoint: endpoint, type: [String:String].self)
} catch let error as NetworkError {
switch error {
case .needRetry, .invalidURL, .emptyData:
throw DomainError.requireRetry
default:
throw DomainError.business(error.description)
}
} catch {
throw DomainError.unknown
}
}
func uploadFile(url: String, data: Data) async throws {
let endPoint = S3Endpoint.uploadImage(uploadURL: url, data: data)
do {
_ = try await networkService.request(endpoint: endPoint, type: EmptyResponseDTO.self)
} catch let error as NetworkError {
switch error {
case .needRetry, .invalidURL, .emptyData:
throw DomainError.requireRetry
default:
throw DomainError.business(error.description)
}
} catch {
throw DomainError.unknown
}
}
}