Skip to content

Commit

Permalink
change file name to hash value
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis972602 committed Feb 14, 2023
1 parent f5ff851 commit 66f3f09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
8 changes: 7 additions & 1 deletion downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ func SetLog(log Log) DownloadOption {
}

func defaultSavePath(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
return fmt.Sprintf(filepath.Join("./download", "%s", "%s", "%s"), utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(attachment.Name))
var name string
if filepath.Ext(attachment.Path) == ".zip" {
name = attachment.Name
} else {
name = filepath.Base(attachment.Path)
}
return fmt.Sprintf(filepath.Join("./download", "%s", "%s", "%s"), utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}

// Async set the async download option
Expand Down
30 changes: 23 additions & 7 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,13 @@ func main() {
if nameRuleOnlyIndex {
ruleflag = true
pathFunc = func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
ext := filepath.Ext(attachment.Name)
name := fmt.Sprintf("%d%s", i, ext)
var name string
if filepath.Ext(attachment.Name) == ".zip" {
name = attachment.Name
} else {
ext := filepath.Ext(attachment.Name)
name = fmt.Sprintf("%d%s", i, ext)
}
return fmt.Sprintf(filepath.Join("%s", "%s", "%s", "%s"), output, utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}
}
Expand All @@ -272,14 +277,20 @@ func main() {
if filepath.Ext(attachment.Name) == ".zip" {
name = attachment.Name
} else {
name = fmt.Sprintf("%d-%s", i, attachment.Name)
name = fmt.Sprintf("%d-%s", i, filepath.Base(attachment.Path))
}
return fmt.Sprintf(filepath.Join("%s", "%s", "%s", "%s"), output, utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}
}
if !ruleflag {
pathFunc = func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
return fmt.Sprintf(filepath.Join("%s", "%s", "%s", "%s"), output, utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(attachment.Name))
var name string
if filepath.Ext(attachment.Name) == ".zip" {
name = attachment.Name
} else {
name = filepath.Base(attachment.Path)
}
return fmt.Sprintf(filepath.Join("%s", "%s", "%s", "%s"), output, utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}
}
downloaderOptions = append(downloaderOptions, downloader.SavePath(pathFunc))
Expand All @@ -291,7 +302,7 @@ func main() {
if filepath.Ext(attachment.Name) == ".zip" {
name = attachment.Name
} else {
name = fmt.Sprintf("%d-%s", i, attachment.Name)
name = fmt.Sprintf("%d-%s", i, filepath.Base(attachment.Path))
}
return fmt.Sprintf(filepath.Join("./download", "%s", "%s", "%s"), utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}
Expand All @@ -301,8 +312,13 @@ func main() {
if nameRuleOnlyIndex {
var pathFunc func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string
pathFunc = func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
ext := filepath.Ext(attachment.Name)
name := fmt.Sprintf("%d%s", i, ext)
var name string
if filepath.Ext(attachment.Name) == ".zip" {
name = attachment.Name
} else {
ext := filepath.Ext(attachment.Name)
name = fmt.Sprintf("%d%s", i, ext)
}
return fmt.Sprintf(filepath.Join("./download", "%s", "%s", "%s"), utils.ValidDirectoryName(creator.Name), utils.ValidDirectoryName(DirectoryName(post)), utils.ValidDirectoryName(name))
}
downloaderOptions = append(downloaderOptions, downloader.SavePath(pathFunc))
Expand Down

0 comments on commit 66f3f09

Please sign in to comment.