From 65ee2390b147485b034569f628b89ac54754a7d3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 6 Nov 2024 16:37:17 +0100 Subject: [PATCH] download: don't retry on 403/404/410 --- download-to-file.go | 4 ++-- download.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/download-to-file.go b/download-to-file.go index d854322a..5421973e 100644 --- a/download-to-file.go +++ b/download-to-file.go @@ -77,12 +77,12 @@ func (cli *Client) DownloadMediaWithPathToFile(directPath string, encFileHash, f // TODO omit hash for unencrypted media? mediaURL := fmt.Sprintf("https://%s%s&hash=%s&mms-type=%s&__wa-mms=", host.Hostname, directPath, base64.URLEncoding.EncodeToString(encFileHash), mmsType) err = cli.downloadAndDecryptToFile(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash, file) - if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) { + if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) || + errors.Is(err, ErrMediaDownloadFailedWith403) || errors.Is(err, ErrMediaDownloadFailedWith404) || errors.Is(err, ErrMediaDownloadFailedWith410) { return err } else if i >= len(mediaConn.Hosts)-1 { return fmt.Errorf("failed to download media from last host: %w", err) } - // TODO there are probably some errors that shouldn't retry cli.Log.Warnf("Failed to download media: %s, trying with next host...", err) } return err diff --git a/download.go b/download.go index faf176ef..f5e02433 100644 --- a/download.go +++ b/download.go @@ -240,12 +240,12 @@ func (cli *Client) DownloadMediaWithPath(directPath string, encFileHash, fileHas // TODO omit hash for unencrypted media? mediaURL := fmt.Sprintf("https://%s%s&hash=%s&mms-type=%s&__wa-mms=", host.Hostname, directPath, base64.URLEncoding.EncodeToString(encFileHash), mmsType) data, err = cli.downloadAndDecrypt(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash) - if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) { + if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) || + errors.Is(err, ErrMediaDownloadFailedWith403) || errors.Is(err, ErrMediaDownloadFailedWith404) || errors.Is(err, ErrMediaDownloadFailedWith410) { return } else if i >= len(mediaConn.Hosts)-1 { return nil, fmt.Errorf("failed to download media from last host: %w", err) } - // TODO there are probably some errors that shouldn't retry cli.Log.Warnf("Failed to download media: %s, trying with next host...", err) } return