-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
feat(feeds): improve RSS size parsing #1367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvements! 👍 Left some comments.
internal/feed/rss_test.go
Outdated
func parseSize(sizeStr string) (uint64, error) { | ||
var multiplier uint64 = 1 | ||
sizeStr = strings.TrimSpace(sizeStr) | ||
|
||
switch { | ||
case strings.HasSuffix(sizeStr, "PiB"): | ||
multiplier = 1024 * 1024 * 1024 * 1024 * 1024 | ||
sizeStr = strings.TrimSuffix(sizeStr, "PiB") | ||
case strings.HasSuffix(sizeStr, "TiB"): | ||
multiplier = 1024 * 1024 * 1024 * 1024 | ||
sizeStr = strings.TrimSuffix(sizeStr, "TiB") | ||
case strings.HasSuffix(sizeStr, "GiB"): | ||
multiplier = 1024 * 1024 * 1024 | ||
sizeStr = strings.TrimSuffix(sizeStr, "GiB") | ||
case strings.HasSuffix(sizeStr, "MiB"): | ||
multiplier = 1024 * 1024 | ||
sizeStr = strings.TrimSuffix(sizeStr, "MiB") | ||
case strings.HasSuffix(sizeStr, "PB"): | ||
multiplier = 1000 * 1000 * 1000 * 1000 * 1000 | ||
sizeStr = strings.TrimSuffix(sizeStr, "PB") | ||
case strings.HasSuffix(sizeStr, "TB"): | ||
multiplier = 1000 * 1000 * 1000 * 1000 | ||
sizeStr = strings.TrimSuffix(sizeStr, "TB") | ||
case strings.HasSuffix(sizeStr, "GB"): | ||
multiplier = 1000 * 1000 * 1000 | ||
sizeStr = strings.TrimSuffix(sizeStr, "GB") | ||
case strings.HasSuffix(sizeStr, "B"): | ||
sizeStr = strings.TrimSuffix(sizeStr, "B") | ||
} | ||
|
||
sizeStr = strings.Replace(sizeStr, " ", "", -1) // Remove any spaces | ||
size, err := strconv.ParseFloat(sizeStr, 64) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to parse size: %v", err) | ||
} | ||
|
||
return uint64(size * float64(multiplier)), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good effort, but humanize.ParseBytes(str)
does this already.
internal/feed/rss.go
Outdated
if matches == nil { | ||
return "" | ||
// pullSizeFromDescription get size from description | ||
func pullSizeFromDescription(str string, r *domain.Release) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick but I think the old name readSizeFromDescription
is better, or parse
instead of read
. we don't use the pull
terminology anywhere else.
No description provided.