Files
hyungi_document_server/clients/ds-app/Sources/DSKit/DownloadURL.swift

22 lines
852 B
Swift

import Foundation
/// Original-file download URL builder. CRITICAL: this endpoint authenticates via the `?token=` QUERY
/// parameter, NOT an Authorization header (iframe/download compatibility). The token must live only in
/// the query. Callers must redact the token when logging the URL.
public enum DSDownload {
public static func fileURL(
base: DSBaseURL,
documentID id: Int,
accessToken: String,
download: Bool = true
) -> URL? {
let endpoint = base.url.appendingPathComponent("documents/\(id)/file")
var comps = URLComponents(url: endpoint, resolvingAgainstBaseURL: false)
comps?.queryItems = [
URLQueryItem(name: "token", value: accessToken),
URLQueryItem(name: "download", value: download ? "true" : "false"),
]
return comps?.url
}
}