Files
2026-07-13 12:22:33 +08:00

34 lines
1.1 KiB
Swift

import Foundation
public struct DeepgramSettingsReader: Sendable {
public static let apiKeyEnvironmentKey = "DEEPGRAM_API_KEY"
public static let projectIDEnvironmentKey = "DEEPGRAM_PROJECT_ID"
public static func apiKey(
environment: [String: String] = ProcessInfo.processInfo.environment) -> String?
{
self.cleaned(environment[self.apiKeyEnvironmentKey])
}
public static func projectID(
environment: [String: String] = ProcessInfo.processInfo.environment) -> String?
{
self.cleaned(environment[self.projectIDEnvironmentKey])
}
private static func cleaned(_ raw: String?) -> String? {
guard var value = raw?.trimmingCharacters(in: .whitespacesAndNewlines), !value.isEmpty else {
return nil
}
if (value.hasPrefix("\"") && value.hasSuffix("\"")) ||
(value.hasPrefix("'") && value.hasSuffix("'"))
{
value = String(value.dropFirst().dropLast())
}
value = value.trimmingCharacters(in: .whitespacesAndNewlines)
return value.isEmpty ? nil : value
}
}