Skip to content

Commit

Permalink
Fixing the CreateVolumeDir option metafates#194
Browse files Browse the repository at this point in the history
  • Loading branch information
Telmo committed Dec 6, 2024
1 parent b017c64 commit 0b504b9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions source/chapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package source

import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/dustin/go-humanize"
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/filesystem"
Expand All @@ -10,11 +16,6 @@ import (
"github.com/metafates/mangal/util"
"github.com/samber/mo"
"github.com/spf13/viper"
"os"
"path/filepath"
"strings"
"sync"
"time"
)

// Chapter is a struct that represents a chapter of a manga.
Expand Down Expand Up @@ -140,19 +141,21 @@ func (c *Chapter) IsDownloaded() bool {
return c.isDownloaded.MustGet()
}

path, _ := c.path(c.Manga.peekPath(), false)
path, _ := c.path(c.Manga.peekPath())
exists, _ := filesystem.Api().Exists(path)
c.isDownloaded = mo.Some(exists)
return exists
}

func (c *Chapter) path(relativeTo string, createVolumeDir bool) (path string, err error) {
if createVolumeDir {
path = filepath.Join(path, util.SanitizeFilename(c.Volume))
func (c *Chapter) path(relativeTo string) (path string, err error) {
if c.Volume != "" && viper.GetBool(key.DownloaderCreateVolumeDir) {
path = filepath.Join(relativeTo, util.SanitizeFilename(c.Volume))
err = filesystem.Api().MkdirAll(path, os.ModePerm)
if err != nil {
return
}
path = filepath.Join(path, c.Filename())
return
}

path = filepath.Join(relativeTo, c.Filename())
Expand All @@ -166,7 +169,7 @@ func (c *Chapter) Path(temp bool) (path string, err error) {
return
}

return c.path(manga, c.Volume != "" && viper.GetBool(key.DownloaderCreateVolumeDir))
return c.path(manga)
}

func (c *Chapter) Source() Source {
Expand Down

0 comments on commit 0b504b9

Please sign in to comment.