mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
feat: add download directory placeholders, category support (#1188)
This commit is contained in:
1 parent
9d9f1caaaa
commit
49b4d99b5e
31 files changed
+1204
-118
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
syspath "path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Dir(path string) string {
|
||||
@@ -199,3 +200,28 @@ func ReplaceInvalidFilename(path string) string {
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// ReplacePathPlaceholders replaces date placeholders in a path with actual values
|
||||
// Supported placeholders:
|
||||
// - %year% - Current year (e.g., 2025)
|
||||
// - %month% - Current month (01-12)
|
||||
// - %day% - Current day (01-31)
|
||||
// - %date% - Full date format (2025-01-01)
|
||||
func ReplacePathPlaceholders(path string) string {
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
year := fmt.Sprintf("%d", now.Year())
|
||||
month := fmt.Sprintf("%02d", now.Month())
|
||||
day := fmt.Sprintf("%02d", now.Day())
|
||||
date := fmt.Sprintf("%s-%s-%s", year, month, day)
|
||||
|
||||
path = strings.ReplaceAll(path, "%year%", year)
|
||||
path = strings.ReplaceAll(path, "%month%", month)
|
||||
path = strings.ReplaceAll(path, "%day%", day)
|
||||
path = strings.ReplaceAll(path, "%date%", date)
|
||||
|
||||
return path
|
||||
}
|
||||
Reference in new issue
Block a user