From c8ec6a8ea75003778256058ea90c16eec23e5cea Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 10 Aug 2022 09:52:58 +0000 Subject: pkg/gcs: construct download URLs in place We cannot request it using the library, so let's do it ourselves. --- pkg/gcs/gcs.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/gcs/gcs.go b/pkg/gcs/gcs.go index 3f7d68ed2..f87e54cab 100644 --- a/pkg/gcs/gcs.go +++ b/pkg/gcs/gcs.go @@ -143,17 +143,18 @@ func (client *Client) DeleteFile(gcsFile string) error { return err } -func (client *Client) GetDownloadURL(gcsFile string) (string, error) { - bucket, filename, err := split(gcsFile) - if err != nil { - return "", err - } - f := client.client.Bucket(bucket).Object(filename) - attrs, err := f.Attrs(client.ctx) - if err != nil { - return "", err +// Where things get published. +const ( + PublicPrefix = "https://storage.googleapis.com/" + AuthenticatedPrefix = "https://storage.cloud.google.com/" +) + +func (client *Client) GetDownloadURL(gcsFile string, publicURL bool) string { + gcsFile = strings.TrimPrefix(gcsFile, "/") + if publicURL { + return PublicPrefix + gcsFile } - return attrs.MediaLink, nil + return AuthenticatedPrefix + gcsFile } type Object struct { @@ -181,9 +182,6 @@ func (client *Client) ListObjects(bucket string) ([]*Object, error) { return ret, nil } -// Where things get published. -const PublicPrefix = "https://storage.googleapis.com/" - func split(file string) (bucket, filename string, err error) { pos := strings.IndexByte(file, '/') if pos == -1 { -- cgit mrf-deployment