ClawdisKit: accept jpg for canvas.snapshot

This commit is contained in:
Peter Steinberger
2025-12-18 23:31:34 +01:00
parent 2307756892
commit 9062f60e3d
2 changed files with 34 additions and 0 deletions

View File

@@ -19,6 +19,24 @@ public struct ClawdisCanvasEvalParams: Codable, Sendable, Equatable {
public enum ClawdisCanvasSnapshotFormat: String, Codable, Sendable {
case png
case jpeg
public init(from decoder: Decoder) throws {
let c = try decoder.singleValueContainer()
let raw = try c.decode(String.self).trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
switch raw {
case "png":
self = .png
case "jpeg", "jpg":
self = .jpeg
default:
throw DecodingError.dataCorruptedError(in: c, debugDescription: "Invalid snapshot format: \(raw)")
}
}
public func encode(to encoder: Encoder) throws {
var c = encoder.singleValueContainer()
try c.encode(self.rawValue)
}
}
public struct ClawdisCanvasSnapshotParams: Codable, Sendable, Equatable {

View File

@@ -0,0 +1,16 @@
import ClawdisKit
import Foundation
import Testing
@Suite struct CanvasSnapshotFormatTests {
@Test func acceptsJpgAlias() throws {
struct Wrapper: Codable {
var format: ClawdisCanvasSnapshotFormat
}
let data = try #require("{\"format\":\"jpg\"}".data(using: .utf8))
let decoded = try JSONDecoder().decode(Wrapper.self, from: data)
#expect(decoded.format == .jpeg)
}
}