Files
sharangandClaude Opus 5.5 2a0a274108
ci / shared (push) Successful in 13s
ci / test (push) Successful in 25m46s
ci / image (push) Successful in 51s
feat(store): Dokumentenablage with areas, checked serving, import (#88)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 13:38:10 +00:00

89 lines
3.2 KiB
Go

package store
import "time"
// Dokumentenablage (0022, workspace ticket #171): a tenant's own documents in
// three areas, each with its original and, once the Factory has delivered it,
// a prepared version (LANE_B_UNIFIED_V5 chunk file, images, cookie-banner
// capture). Everything is addressed by SHA-256 and checked when it is served.
const (
AreaLegalWeb = "legal_web" // Rechtliche Website-Dokumente
AreaProductPublic = "product_public" // Produktdokumente (öffentlich)
AreaInternal = "internal" // Interne Dokumente
ProcessingNone = "none"
ProcessingPending = "pending"
ProcessingReady = "ready"
ProcessingFailed = "failed"
)
// LegalKinds are the folders of the legal website documents, in display
// order, with the codes the workspace and the Factory use.
var LegalKinds = []string{"impressum", "dse", "cookie", "agb", "widerruf", "barrierefreiheit", "entsorgung", "vsbg"}
// ValidArea reports whether area is one of the three store areas.
func ValidArea(area string) bool {
return area == AreaLegalWeb || area == AreaProductPublic || area == AreaInternal
}
// ValidLegalKind reports whether kind is one of the legal folders.
func ValidLegalKind(kind string) bool {
for _, k := range LegalKinds {
if k == kind {
return true
}
}
return false
}
// validStoreFields: a legal kind exactly for legal documents, a known area,
// a known status.
func validStoreFields(d Document) bool {
if d.Area == "" {
return d.LegalKind == "" && d.ExternalID == ""
}
if !ValidArea(d.Area) || (d.Area == AreaLegalWeb) != (d.LegalKind != "") {
return false
}
if d.LegalKind != "" && !ValidLegalKind(d.LegalKind) {
return false
}
switch d.ProcessingStatus {
case "", ProcessingNone, ProcessingPending, ProcessingReady, ProcessingFailed:
return len(d.ExternalID) <= 120
}
return false
}
// Preparation is the prepared version of a document as delivered. The chunk
// part and the consent part are delivered independently; either may be empty.
type Preparation struct {
DocumentID string `json:"document_id"`
Format string `json:"format,omitempty"`
Revision int `json:"revision,omitempty"`
Pin string `json:"pin,omitempty"`
ChunkObjectKey string `json:"-"`
ChunkSHA256 string `json:"chunk_sha256,omitempty"`
ChunkBytes int64 `json:"chunk_bytes,omitempty"`
ChunkCount int `json:"chunk_count"`
ConsentObjectKey string `json:"-"`
ConsentSHA256 string `json:"consent_sha256,omitempty"`
AssetDigests []string `json:"asset_digests"`
DeliveredBy string `json:"delivered_by,omitempty"`
DeliveredAt time.Time `json:"delivered_at"`
}
// HasChunks and HasConsent say which parts are there.
func (p Preparation) HasChunks() bool { return p.ChunkSHA256 != "" }
func (p Preparation) HasConsent() bool { return p.ConsentSHA256 != "" }
// StoreAsset is one image of a tenant's prepared documents.
type StoreAsset struct {
TenantID string `json:"tenant_id"`
SHA256 string `json:"sha256"`
ObjectKey string `json:"-"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
CreatedAt time.Time `json:"created_at"`
}