Skip to content

Commit

Permalink
modified: models/policy.go (#1718)
Browse files Browse the repository at this point in the history
modified:   models/policy_test.go
  • Loading branch information
Arkylin authored May 24, 2023
1 parent 00d56d6 commit 6358740
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (policy *Policy) GenerateFileName(uid uint, origin string) string {
"{second}": time.Now().Format("05"),
"{originname}": origin,
"{ext}": filepath.Ext(origin),
"{originname_without_ext}": strings.TrimSuffix(origin, filepath.Ext(origin)),
"{uuid}": uuid.Must(uuid.NewV4()).String(),
}

Expand Down
6 changes: 6 additions & 0 deletions models/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func TestPolicy_GenerateFileName(t *testing.T) {
testPolicy.FileNameRule = "123{date}ss{datetime}"
asserts.Len(testPolicy.GenerateFileName(1, "123.txt"), 27)

testPolicy.FileNameRule = "{originname_without_ext}"
asserts.Len(testPolicy.GenerateFileName(1, "123.txt"), 3)

testPolicy.FileNameRule = "{originname_without_ext}_{randomkey8}{ext}"
asserts.Len(testPolicy.GenerateFileName(1, "123.txt"), 16)

// 支持{originname}的策略
testPolicy.Type = "local"
testPolicy.FileNameRule = "123{originname}"
Expand Down

0 comments on commit 6358740

Please sign in to comment.