Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

@@ -234,6 +234,16 @@ struct SoftwareLibraryRelease: Identifiable, Codable, Sendable {
}
}
try SoftwareLibraryOwnedGame.validateBrowseMetadata(metadata, optional: true)
if metadata["related_archive"] != .null {
guard metadata["related_archive_contract"].integer == 1, case .array(let references) = metadata["related_archive"], references.count <= 100 else {
throw SoftwareLibraryCatalog.Failure.invalid("unsupported related Archive document contract")
}
let parsed = try references.map(SoftwareLibraryRelatedReference.parse)
guard Set(parsed.map(\.id)).count == parsed.count,
Set(parsed.map { $0.documentID + ":" + String($0.page ?? 0) }).count == parsed.count else {
throw SoftwareLibraryCatalog.Failure.invalid("duplicate related Archive document relationship")
}
}
}
var publisher: String? { metadata["publisher"].string }
var year: Int? { metadata["year"].integer }
@@ -624,3 +634,46 @@ private extension Dictionary where Key == String, Value == String {
return value
}
}
/// Reviewed cross-library relationships are public metadata, never transport URLs.
struct SoftwareLibraryRelatedReference: Identifiable, Sendable {
let id: String
let title: String
let documentID: String
let sha256: String
let role: String
let page: Int?
let spoiler: Bool
let order: Int
static let roles = ["Guide", "Tutorial", "Reference", "Hints", "Walkthrough", "Solution", "Map"]
static func parse(_ json: LibraryJSON) throws -> Self {
guard let id = json["id"].string, !id.isEmpty, id.utf8.count <= 240,
let title = json["title"].string, !title.isEmpty, title.utf8.count <= 1000,
let document = json["document_id"].string, document.count == 64, document.allSatisfy(\.isHexDigit),
let sha = json["sha256"].string, sha == document,
let role = json["role"].string, roles.contains(role),
json["page"] == .null || (json["page"].integer ?? 0) > 0 else {
throw SoftwareLibraryCatalog.Failure.invalid("invalid related Archive document metadata")
}
return .init(id: id, title: title, documentID: document, sha256: sha, role: role,
page: json["page"].integer, spoiler: json["spoiler"] == .bool(true), order: json["order"].integer ?? 999)
}
}
extension SoftwareLibraryRelease {
var isDirectSubmission: Bool { metadata["origin"].string == "direct_submission" }
var isArchive: Bool { ownedGame == nil && !isPersonal && !isDirectSubmission }
var relatedArchiveReferences: [SoftwareLibraryRelatedReference] {
guard metadata["related_archive_contract"].integer == 1 else { return [] }
return metadata["related_archive"].array.compactMap { try? SoftwareLibraryRelatedReference.parse($0) }.sorted {
if $0.order != $1.order { return $0.order < $1.order }
let a = SoftwareLibraryRelatedReference.roles.firstIndex(of: $0.role) ?? 99
let b = SoftwareLibraryRelatedReference.roles.firstIndex(of: $1.role) ?? 99
if a != b { return a < b }
return $0.title.localizedStandardCompare($1.title) == .orderedAscending
}
}
}
extension SoftwareLibraryRelease {
var isPersonal: Bool { metadata["personal"] == .bool(true) && titleID.hasPrefix("personal:") }
}