Skip to content

Commit 58e581c

Browse files
Improve type conversion (#628)
* Fix type conversion * Update changelog.md * ci: replace youtube-dl instead of yt-dlp
1 parent d4d8a51 commit 58e581c

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

.github/workflows/testing.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ jobs:
121121
# search package https://pkgs.org/
122122
sudo add-apt-repository universe
123123
sudo apt-get -y -qq update
124-
sudo apt-get -y -qq install ffmpeg webp youtube-dl
124+
sudo apt-get -y -qq install ffmpeg webp yt-dlp
125125
pip3 install you-get
126-
echo "youtube-dl version $(youtube-dl --version)"
126+
echo "yt-dlp version $(yt-dlp --version)"
127127
you-get --version
128128
ffmpeg -version
129129

config/options.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"path"
11+
"strconv"
1112
"strings"
1213
"sync"
1314
"time"
@@ -927,7 +928,12 @@ func (o *Options) WaybackTimeout() time.Duration {
927928

928929
// WaybackMaxRetries returns max retries for a wayback request.
929930
func (o *Options) WaybackMaxRetries() uint64 {
930-
return uint64(o.waybackMaxRetries)
931+
s := strconv.Itoa(o.waybackMaxRetries)
932+
u, err := strconv.ParseUint(s, 10, 64)
933+
if err != nil {
934+
return 0
935+
}
936+
return u
931937
}
932938

933939
// WaybackUserAgent returns User-Agent for a wayback request.

docs/changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Fixed
1818
- Fix playback from discord no response
1919
- Improve IRC publish
20+
- Improve type conversion ([#628](https://github.com/wabarc/wayback/pull/628))
2021

2122
## [0.20.1] - 2024-07-02
2223

service/discord/discord.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ func (d *Discord) buttonHandlers() map[string]func(*discord.Session, *discord.In
205205
}
206206

207207
// Query playback callback data from database
208-
pb, err := d.store.Playback(uint64(id))
208+
x := strconv.Itoa(id)
209+
u, err := strconv.ParseUint(x, 10, 64)
210+
if err != nil {
211+
logger.Error("parse uint failed: %v", err)
212+
return
213+
}
214+
pb, err := d.store.Playback(u)
209215
if err != nil {
210216
logger.Error("query playback data failed: %v", err)
211217
metrics.IncrementWayback(metrics.ServiceDiscord, metrics.StatusFailure)

service/telegram/telegram.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ func (t *Telegram) Serve() (err error) {
119119
}
120120

121121
// Query playback callback data from database
122-
pb, err := t.store.Playback(uint64(id))
122+
x := strconv.Itoa(id)
123+
u, err := strconv.ParseUint(x, 10, 64)
124+
if err != nil {
125+
logger.Error("parse uint failed: %v", err)
126+
return false
127+
}
128+
pb, err := t.store.Playback(u)
123129
if err != nil {
124130
logger.Error("query playback data failed: %v", err)
125131
metrics.IncrementWayback(metrics.ServiceTelegram, metrics.StatusFailure)

service/utils.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path"
1111
"path/filepath"
12+
"strconv"
1213
"strings"
1314
"sync"
1415

@@ -103,7 +104,13 @@ func filterArtifact(art reduxer.Artifact, upper int64) (paths []string) {
103104
}
104105
fsize += helper.FileSize(asset.Local)
105106
if fsize > upper {
106-
logger.Warn("total file size large than %s, skipped", humanize.Bytes(uint64(upper)))
107+
s := strconv.FormatInt(upper, 10)
108+
u, err := strconv.ParseUint(s, 10, 64)
109+
if err != nil {
110+
logger.Warn("parse uint failed %v", err)
111+
continue
112+
}
113+
logger.Warn("total file size large than %s, skipped", humanize.Bytes(u))
107114
continue
108115
}
109116
paths = append(paths, asset.Local)

0 commit comments

Comments
 (0)