bugger/Sources/Utils/URL+Feishu.swift

32 lines
1.0 KiB
Swift

import Foundation
enum FeishuURLBuilder {
static func recordURL(
baseDomain: String,
appToken: String,
tableId: String,
recordId: String
) -> URL? {
// Feishu Bitable record deep link: uses query parameters.
// Returns nil for malformed inputs (e.g. config containing spaces or
// slashes) instead of force-unwrapping and crashing.
var components = URLComponents()
components.scheme = "https"
components.host = baseDomain
components.path = "/base/\(appToken)"
components.queryItems = [
URLQueryItem(name: "table", value: tableId),
URLQueryItem(name: "record", value: recordId)
]
return components.url
}
static func tableURL(baseDomain: String, appToken: String) -> URL? {
var components = URLComponents()
components.scheme = "https"
components.host = baseDomain
components.path = "/base/\(appToken)"
return components.url
}
}