diff options
Diffstat (limited to 'pkg/gcs')
| -rw-r--r-- | pkg/gcs/gcs.go | 24 |
1 files 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 { |
