package store import ( "context" "time" "pageswiki/internal/geduldh" ) // MaterializeDocument supplies a verified node-local, read-only scratch copy // for tools needing a pathname. Callers must authorize the reference first and // close the lease after all subprocesses finish. DB-only legacy stores work too. // TMPDIR is the operator-controlled local scratch root, not DocumentRoot. func (s *Store) MaterializeDocument(ctx context.Context, hash string, maxBytes int64) (*geduldh.Lease, error) { s.documentMaterializerOnce.Do(func() { // These fixed safe defaults precede configurable deployment profiles. s.documentMaterializer, _ = geduldh.NewMaterializer(documentSource{s}, geduldh.MaterializeOptions{ MaxBytes: 2 << 30, Concurrent: 2, Timeout: 2 * time.Minute, }) }) return s.documentMaterializer.Acquire(ctx, hash, maxBytes) } type documentSource struct{ store *Store } func (source documentSource) Stat(ctx context.Context, hash string) (geduldh.Info, error) { size, err := source.store.DocumentSizeContext(ctx, hash) return geduldh.Info{Hash: hash, Size: size}, err } func (source documentSource) Open(ctx context.Context, hash string) (geduldh.Reader, error) { return source.store.OpenDocumentContext(ctx, hash) }