Validate compiled Suno output
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
public protocol SunoOutputValidating: Sendable {
|
||||
func validate(_ output: CompiledSunoOutput) throws
|
||||
}
|
||||
|
||||
public enum SunoOutputValidationError: Error, Equatable, LocalizedError, Sendable {
|
||||
case missingContent
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .missingContent:
|
||||
return "Add lyrics or a style prompt before sending the song to Suno."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct CompiledSunoOutputValidator: SunoOutputValidating {
|
||||
public init() {}
|
||||
|
||||
public func validate(_ output: CompiledSunoOutput) throws {
|
||||
let lyrics = output.lyricsText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let style = output.stylePrompt.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
guard !lyrics.isEmpty || !style.isEmpty else {
|
||||
throw SunoOutputValidationError.missingContent
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user