Skip to content

Commit

Permalink
feat: optimize naming
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxsen committed Dec 20, 2024
1 parent 5103ac9 commit 764a445
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
23 changes: 13 additions & 10 deletions capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"yamdc/utils"

"github.com/xxxsen/common/logutil"
"github.com/xxxsen/common/replacer"
"github.com/xxxsen/common/trace"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -137,20 +138,22 @@ func (c *Capture) processFileList(ctx context.Context, fcs []*model.FileContext)
}

func (c *Capture) resolveSaveDir(fc *model.FileContext) error {
now := time.UnixMilli(fc.Meta.ReleaseDate)
date := now.Format(time.DateOnly)
year := fmt.Sprintf("%d", now.Year())
month := fmt.Sprintf("%d", now.Month())
ts := time.UnixMilli(fc.Meta.ReleaseDate)
date := ts.Format(time.DateOnly)
year := fmt.Sprintf("%d", ts.Year())
month := fmt.Sprintf("%d", ts.Month())
actor := "佚名"
if len(fc.Meta.Actors) > 0 {
actor = utils.BuildAuthorsName(fc.Meta.Actors, 256)
}
naming := c.c.Naming
naming = strings.ReplaceAll(naming, NamingReleaseDate, date)
naming = strings.ReplaceAll(naming, NamingReleaseYear, year)
naming = strings.ReplaceAll(naming, NamingReleaseMonth, month)
naming = strings.ReplaceAll(naming, NamingActor, actor)
naming = strings.ReplaceAll(naming, NamingNumber, fc.Number.GetNumberID())
m := map[string]interface{}{
NamingReleaseDate: date,
NamingReleaseYear: year,
NamingReleaseMonth: month,
NamingActor: actor,
NamingNumber: fc.Number.GetNumberID(),
}
naming := replacer.ReplaceByMap(c.c.Naming, m)
if len(naming) == 0 {
return fmt.Errorf("invalid naming")
}
Expand Down
10 changes: 5 additions & 5 deletions capture/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
)

const (
NamingReleaseDate = "{DATE}"
NamingReleaseYear = "{YEAR}"
NamingReleaseMonth = "{MONTH}"
NamingActor = "{ACTOR}"
NamingNumber = "{NUMBER}"
NamingReleaseDate = "DATE"
NamingReleaseYear = "YEAR"
NamingReleaseMonth = "MONTH"
NamingActor = "ACTOR"
NamingNumber = "NUMBER"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require (
github.com/google/uuid v1.6.0
github.com/imroc/req/v3 v3.48.0
github.com/stretchr/testify v1.9.0
github.com/xxxsen/common v0.1.11
github.com/xxxsen/common v0.1.13
go.uber.org/zap v1.23.0
golang.org/x/image v0.18.0
golang.org/x/net v0.29.0
golang.org/x/net v0.33.0
golang.org/x/text v0.21.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xxxsen/common v0.1.11 h1:HQaeXMuqVZF5YlNa7N5at+hrjp8BW2Ll2lmDda/xhRU=
github.com/xxxsen/common v0.1.11/go.mod h1:Xz804Aj8T0vh+EF6zO8d8SJclwptoc6mx24lpXCauuY=
github.com/xxxsen/common v0.1.13 h1:/caSfUt3FOMGPE278jUG+clh/HYP8YpcDAzW6qM1zDg=
github.com/xxxsen/common v0.1.13/go.mod h1:39hYpTTRGbdlyXn3TfE+b0LWjyS3xIKJlt+BvcKBY0Q=
github.com/xxxsen/go-face v0.0.1 h1:l64Xyi+LkNbRxWmuPphW/VsEW9y97h99sil6IHiOSus=
github.com/xxxsen/go-face v0.0.1/go.mod h1:9wdDJkRgo3SGTcFwbQ7elVIQhIr2bbBjecuY7VoqmPU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down Expand Up @@ -99,8 +99,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
Expand Down
2 changes: 1 addition & 1 deletion searcher/default_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
defaultPageSearchCacheExpire = 1 * time.Hour
defaultPageSearchCacheExpire = 30 * 24 * time.Hour
)

type DefaultSearcher struct {
Expand Down

0 comments on commit 764a445

Please sign in to comment.