Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type conversion #628

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ jobs:
# search package https://pkgs.org/
sudo add-apt-repository universe
sudo apt-get -y -qq update
sudo apt-get -y -qq install ffmpeg webp youtube-dl
sudo apt-get -y -qq install ffmpeg webp yt-dlp
pip3 install you-get
echo "youtube-dl version $(youtube-dl --version)"
echo "yt-dlp version $(yt-dlp --version)"
you-get --version
ffmpeg -version

Expand Down
8 changes: 7 additions & 1 deletion config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"net/url"
"os"
"path"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -927,7 +928,12 @@

// WaybackMaxRetries returns max retries for a wayback request.
func (o *Options) WaybackMaxRetries() uint64 {
return uint64(o.waybackMaxRetries)
s := strconv.Itoa(o.waybackMaxRetries)
u, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return 0
}

Check warning on line 935 in config/options.go

View check run for this annotation

Codecov / codecov/patch

config/options.go#L934-L935

Added lines #L934 - L935 were not covered by tests
return u
}

// WaybackUserAgent returns User-Agent for a wayback request.
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fix playback from discord no response
- Improve IRC publish
- Improve type conversion ([#628](https://github.com/wabarc/wayback/pull/628))

## [0.20.1] - 2024-07-02

Expand Down
8 changes: 7 additions & 1 deletion service/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@
}

// Query playback callback data from database
pb, err := d.store.Playback(uint64(id))
x := strconv.Itoa(id)
u, err := strconv.ParseUint(x, 10, 64)
if err != nil {
logger.Error("parse uint failed: %v", err)
return
}
pb, err := d.store.Playback(u)

Check warning on line 214 in service/discord/discord.go

View check run for this annotation

Codecov / codecov/patch

service/discord/discord.go#L208-L214

Added lines #L208 - L214 were not covered by tests
if err != nil {
logger.Error("query playback data failed: %v", err)
metrics.IncrementWayback(metrics.ServiceDiscord, metrics.StatusFailure)
Expand Down
8 changes: 7 additions & 1 deletion service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@
}

// Query playback callback data from database
pb, err := t.store.Playback(uint64(id))
x := strconv.Itoa(id)
u, err := strconv.ParseUint(x, 10, 64)
if err != nil {
logger.Error("parse uint failed: %v", err)
return false
}
pb, err := t.store.Playback(u)

Check warning on line 128 in service/telegram/telegram.go

View check run for this annotation

Codecov / codecov/patch

service/telegram/telegram.go#L122-L128

Added lines #L122 - L128 were not covered by tests
if err != nil {
logger.Error("query playback data failed: %v", err)
metrics.IncrementWayback(metrics.ServiceTelegram, metrics.StatusFailure)
Expand Down
9 changes: 8 additions & 1 deletion service/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"os"
"path"
"path/filepath"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -103,7 +104,13 @@
}
fsize += helper.FileSize(asset.Local)
if fsize > upper {
logger.Warn("total file size large than %s, skipped", humanize.Bytes(uint64(upper)))
s := strconv.FormatInt(upper, 10)
u, err := strconv.ParseUint(s, 10, 64)
if err != nil {
logger.Warn("parse uint failed %v", err)
continue

Check warning on line 111 in service/utils.go

View check run for this annotation

Codecov / codecov/patch

service/utils.go#L107-L111

Added lines #L107 - L111 were not covered by tests
}
logger.Warn("total file size large than %s, skipped", humanize.Bytes(u))

Check warning on line 113 in service/utils.go

View check run for this annotation

Codecov / codecov/patch

service/utils.go#L113

Added line #L113 was not covered by tests
continue
}
paths = append(paths, asset.Local)
Expand Down
Loading