diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-08-10 09:52:58 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-08-24 12:05:06 +0200 |
| commit | c8ec6a8ea75003778256058ea90c16eec23e5cea (patch) | |
| tree | b7411fa1fc3a7fdb55138921b929977f548291e7 /pkg | |
| parent | cea8b0f72c56f0c82a465154bb7412407e78dcd8 (diff) | |
pkg/gcs: construct download URLs in place
We cannot request it using the library, so let's do it ourselves.
Diffstat (limited to 'pkg')
| -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 { |
