Photos post on PDSes that still require alt
Grain/Services/GalleryDraft.swift+3−4
| @@ -106,10 +106,9 @@ struct GalleryDraft: Codable, Sendable, Identifiable, Equatable { | ||
] as [String: AnyCodable]), | ||
"createdAt": AnyCodable(createdAt), | ||
] | ||
let alt = photo.alt.trimmingCharacters(in: .whitespacesAndNewlines) | ||
if !alt.isEmpty { | ||
record["alt"] = AnyCodable(alt) | ||
} | ||
// Always sent: the PDS validates against its own compiled-in copy of | ||
// this schema, which requires alt even when it is empty. | ||
record["alt"] = AnyCodable(photo.alt.trimmingCharacters(in: .whitespacesAndNewlines)) | ||
writes.append(.create(collection: "social.grain.photo", rkey: photo.photoRkey, value: AnyCodable(record))) | ||
| ||
if includeExif, var exif = photo.exif, !exif.isEmpty { | ||
GrainTests/GalleryPublishTests.swift+12−0
| @@ -196,6 +196,18 @@ final class GalleryPublishTests: GrainTestCase { | ||
XCTAssertTrue(writes.allSatisfy { TID.isValid($0.rkey) }) | ||
} | ||
| ||
/// A PDS refuses a photo with no alt key, so a photo without a description | ||
/// still has to send one. | ||
func testEveryPhotoWriteCarriesAlt() throws { | ||
let draft = try makeDraft(photoCount: 2, uploaded: 2) | ||
let photos = draft.writes().filter { $0.collection == "social.grain.photo" } | ||
XCTAssertEqual(photos.count, 2) | ||
for write in photos { | ||
let record = try JSONSerialization.jsonObject(with: JSONEncoder().encode(write.value)) as? [String: Any] | ||
XCTAssertNotNil(record?["alt"] as? String) | ||
} | ||
} | ||
| ||
/// A photo whose blob never made it up must not produce a dangling item | ||
/// record pointing at a photo that doesn't exist. | ||
func testWritesSkipPhotosWithoutBlobs() throws { | ||