Source code for satorbis_kit.pgstac.uploader.default
"""Default STAC upload handler implementation."""
from __future__ import annotations
from typing import Optional
from .base import AbstractRasterUploadHandler
from .utils import sanitize_collection, validate_stac_filename
[docs]
class DefaultRasterUploadHandler(AbstractRasterUploadHandler):
"""Builds remote paths that follow the GenericMetaExtractor expectations."""
DEFAULT_SUBFOLDER = ""
[docs]
def build_remote_path(
self,
collection: str,
filename: str,
subfolder: Optional[str] = None,
) -> str:
sanitized_collection = sanitize_collection(collection)
validate_stac_filename(filename)
selected_folder = self.DEFAULT_SUBFOLDER if subfolder is None else subfolder
folder = selected_folder.strip("/")
segments = [segment for segment in [sanitized_collection, folder, filename] if segment]
return "/".join(segments)