Files
hyungi_document_server/Sources/DSKit/DownloadURL.swift
T
Hyungi 0becf7829e feat(s3): SwiftPM scaffold + DSKit data layer + 14-fixture acceptance
- Package.swift: AI (S2-owned) + DSKit (models/client/fixtures) + DSKitTests, tools 6.2, .swiftLanguageMode(.v6), .macOS(.v26)
- JSONValue (Sendable AnyCodable), DSDate (value-type ISO8601FormatStyle cascade, date-only UTC), explicit-CodingKeys decoder
- Models: Auth/Document(+Detail flat-compose, MD-first)/Catalog/Search+Ask/Memo/Digest; non-optional limited to id/file_type/created+updated_at/total
- DSClient protocol + FixtureDSClient (Bundle.module, zero backend) + DSError + DSConfig + DownloadURL (?token= query)
- Tests: 14-fixture contract acceptance (value asserts) + JSONValue number trap + Ask round-trip + AI router fallback/explicit-unavailable

swift build + swift test green (19 tests). Sources/AI untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 17:16:55 +09:00

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
}
}