hako/internal/model/storage.go

38 lines
1.3 KiB
Go

package model
import (
"context"
"io"
)
// Storage defines the interface for file storage operations
type Storage interface {
// Save stores a file and returns the storage path
Save(ctx context.Context, linkID string, filename string, reader io.Reader) (path string, err error)
// Get retrieves a file from storage
Get(ctx context.Context, path string) (io.ReadCloser, error)
// Delete removes a file from storage
Delete(ctx context.Context, path string) error
// Exists checks if a file exists in storage
Exists(ctx context.Context, path string) (bool, error)
// DeleteDirectory removes an entire link directory and all its contents
DeleteDirectory(ctx context.Context, linkID string) error
}
// GetPathForLink returns the relative storage path for a link directory.
// The path is relative to the storage base path.
// Example: GetPathForLink("abc-123") returns "abc-123"
func GetPathForLink(linkID string) string {
return "links/" + linkID
}
// GetPathForLinkFile returns the relative storage path for a file within a link directory.
// The path is relative to the storage base path.
// Example: GetPathForLinkFile("abc-123", "document.pdf") returns "abc-123/document.pdf"
func GetPathForLinkFile(linkID, filename string) string {
return GetPathForLink(linkID) + "/" + filename
}