def get_local_url()

in aidial_adapter_dial/transformer.py [0:0]


    def get_local_url(self, remote_url: str) -> str:
        """
        user/app files uploaded from local to remote earlier (reverse of get_remote_url):
            if proxy_mode:
                < files/REMOTE_USER_BUCKET/PATH
                > files/LOCAL_USER_BUCKET/PATH
            else:
                < files/REMOTE_USER_BUCKET/LOCAL_USER_BUCKET/PATH
                > files/LOCAL_USER_BUCKET/PATH

        created by remote (user):
            < files/REMOTE_USER_BUCKET/appdata/REMOTE_APP_NAME/PATH
            > files/LOCAL_USER_BUCKET/appdata/LOCAL_APP_NAME/PATH

        created by remote (app):
            < files/REMOTE_APP_BUCKET/PATH
            > This means an application has a bug in it.
                We reject such URLs right away since there is no way
                to read an application file by a user.
        """

        if not remote_url.startswith(f"files/{self.remote_user_bucket}/"):
            raise ValueError(
                f"The remote file ({remote_url!r}) is expected "
                f"to be uploaded to the remote user bucket ({self.remote_user_bucket!r})"
            )

        remote_path = remote_url.removeprefix(
            f"files/{self.remote_user_bucket}/"
        )

        if remote_path.startswith("appdata/"):
            regex = r"appdata/([^/]+)/(.+)"
            match = re.match(regex, remote_path)
            if match is None:
                raise ValueError(f"Invalid remote appdata path: {remote_url!r}")
            _remote_app_name, path = match.groups()
            return f"files/{self.local_appdata}/{path}"

        if not self.proxy_mode:
            if remote_path.startswith(f"{self.local_user_bucket}/"):
                path = remote_path.removeprefix(f"{self.local_user_bucket}/")
                return f"files/{self.local_user_bucket}/{path}"

            raise ValueError(
                f"The remote file ({remote_url!r}) is expected to be uploaded either "
                "to remote appdata path or "
                "to a local user bucket subpath of remote user bucket."
            )
        else:
            return remote_url