fix: support Gitea 28.0.0 mail templates
Release / Validate Templates (push) Canceled after 0s
Release / Package & Release (push) Canceled after 0s

This commit is contained in:
KenanZhu committed 2026-10-02 19:44:20 +08:00
1 parent ffb674669b
commit 92d2ba9889
18 files changed
+135 -42

No files matched your search

+17 -5
View File
@@ -15,10 +15,10 @@ var TemplateFuncs = template.FuncMap{
"QueryEscape": url.QueryEscape,
"ShortSha": ShortSha,
"PathEscapeSegments": PathEscapeSegments,
"FileSize": FileSize,
"FormatByteSize": previewFormatByteSize,
"HTMLFormat": HTMLFormat,
"Dict": Dict,
"gt": Gt, // override built-in for JSON float64/int coercion
"gt": Gt, // override built-in for JSON float64/int coercion
"lt": Lt,
"ge": Ge,
"le": Le,
@@ -41,8 +41,20 @@ func PathEscapeSegments(s string) string {
return strings.Join(parts, "/")
}
// FileSize formats a byte count as a human-readable string (e.g. "2.5 MB").
func FileSize(n int64) string {
// previewFormatByteSize converts JSON fixture numbers to Gitea's int64 input type.
func previewFormatByteSize(size any) (string, error) {
switch n := size.(type) {
case int64:
return FormatByteSize(n), nil
case float64:
return FormatByteSize(int64(n)), nil
default:
return "", fmt.Errorf("FormatByteSize: unsupported size type %T", size)
}
}
// FormatByteSize mirrors Gitea 28's IEC attachment size formatting.
func FormatByteSize(n int64) string {
const unit = 1024
if n < unit {
return fmt.Sprintf("%d B", n)
@@ -52,7 +64,7 @@ func FileSize(n int64) string {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %s", float64(n)/float64(div), []string{"KB", "MB", "GB", "TB"}[exp])
return fmt.Sprintf("%.1f %s", float64(n)/float64(div), []string{"KiB", "MiB", "GiB", "TiB"}[exp])
}
// HTMLFormat substitutes %s/%d placeholders with HTML-escaped values.