feat: Remove geometry and properties from GET /datasets/{id} endpoint, new endpoint for download cog file
This commit is contained in:
@@ -22,6 +22,15 @@ import (
|
||||
// maxParseBytes caps how much of a file is read into memory for parsing.
|
||||
const maxParseBytes = 256 << 20 // 256 MiB
|
||||
|
||||
var (
|
||||
// ErrNotRaster is returned when a raster-only operation is requested for a
|
||||
// non-raster dataset.
|
||||
ErrNotRaster = errors.New("dataset is not a raster")
|
||||
// ErrCOGNotReady is returned when a raster's Cloud-Optimized GeoTIFF has not
|
||||
// been produced yet.
|
||||
ErrCOGNotReady = errors.New("cog is not ready")
|
||||
)
|
||||
|
||||
// DatasetRepository is the persistence behaviour DatasetService needs.
|
||||
type DatasetRepository interface {
|
||||
Create(ctx context.Context, d domain.Dataset) (domain.Dataset, error)
|
||||
@@ -958,6 +967,27 @@ func (s *DatasetService) Download(ctx context.Context, id uuid.UUID) (domain.Dat
|
||||
return dataset, obj, nil
|
||||
}
|
||||
|
||||
// COG returns the dataset metadata and a reader for its Cloud-Optimized GeoTIFF.
|
||||
// It fails with ErrNotRaster for non-raster datasets and ErrCOGNotReady when the
|
||||
// raster has not been converted yet. The caller must close the reader.
|
||||
func (s *DatasetService) COG(ctx context.Context, id uuid.UUID) (domain.Dataset, io.ReadCloser, error) {
|
||||
dataset, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return domain.Dataset{}, nil, err
|
||||
}
|
||||
if dataset.FileType != domain.FileTypeRaster {
|
||||
return domain.Dataset{}, nil, ErrNotRaster
|
||||
}
|
||||
if dataset.CogStorageKey == nil {
|
||||
return domain.Dataset{}, nil, ErrCOGNotReady
|
||||
}
|
||||
obj, err := s.store.Get(ctx, *dataset.CogStorageKey)
|
||||
if err != nil {
|
||||
return domain.Dataset{}, nil, err
|
||||
}
|
||||
return dataset, obj, nil
|
||||
}
|
||||
|
||||
// Delete removes the dataset row and its stored object.
|
||||
func (s *DatasetService) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
dataset, err := s.repo.GetByID(ctx, id)
|
||||
|
||||
Reference in New Issue
Block a user