Files
Acbox 3fa311c6cb fix(media): proxy ContainerFileOpener through fallback storage provider
The fallback provider introduced in 5aeb2fd3 wrapped containerfs but did
not implement storage.ContainerFileOpener, causing IngestContainerFile to
fail with "provider does not support container file reading". This broke
outbound file attachments on all IM channels (Telegram, Discord, etc.)
because container paths like /data/xxx.xlsx were passed as-is to the
platform API instead of being ingested into the media store first.
2026-04-03 01:14:20 +08:00

38 lines
1.4 KiB
Go

// Package storage defines the Provider interface for object storage backends.
package storage
import (
"context"
"errors"
"io"
)
// ErrContainerFileNotSupported is returned when no underlying provider
// implements ContainerFileOpener.
var ErrContainerFileNotSupported = errors.New("provider does not support container file reading")
// Provider abstracts object storage operations.
type Provider interface {
// Put writes data to storage under the given key.
Put(ctx context.Context, key string, reader io.Reader) error
// Open returns a reader for the given storage key.
Open(ctx context.Context, key string) (io.ReadCloser, error)
// Delete removes the object at key.
Delete(ctx context.Context, key string) error
// AccessPath returns a consumer-accessible reference for a storage key.
// The format depends on the backend (e.g. container path, signed URL).
AccessPath(key string) string
}
// ContainerFileOpener is an optional interface that providers can implement
// to open arbitrary files from a bot's container data directory.
type ContainerFileOpener interface {
OpenContainerFile(ctx context.Context, botID, containerPath string) (io.ReadCloser, error)
}
// PrefixLister is an optional interface for providers that can list keys
// sharing a common prefix (e.g. directory listing on a filesystem backend).
type PrefixLister interface {
ListPrefix(ctx context.Context, prefix string) ([]string, error)
}