mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 22:03:41 +00:00
feat: auto rename on duplicate (#76)
This commit is contained in:
1 parent
048554df4d
commit
0515ce6081
8 files changed
+205
-152
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/monkeyWie/gopeed/internal/fetcher"
|
||||
"github.com/monkeyWie/gopeed/pkg/base"
|
||||
"github.com/monkeyWie/gopeed/pkg/util"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -74,15 +75,16 @@ func (f *Fetcher) Resolve(req *base.Request) error {
|
||||
}
|
||||
defer f.torrent.Drop()
|
||||
res := &base.Resource{
|
||||
Name: f.torrent.Name(),
|
||||
Range: true,
|
||||
Files: make([]*base.FileInfo, len(f.torrent.Files())),
|
||||
Hash: f.torrent.InfoHash().String(),
|
||||
Name: f.torrent.Name(),
|
||||
Range: true,
|
||||
RootDir: f.torrent.Name(),
|
||||
Files: make([]*base.FileInfo, len(f.torrent.Files())),
|
||||
Hash: f.torrent.InfoHash().String(),
|
||||
}
|
||||
for i, file := range f.torrent.Files() {
|
||||
res.Files[i] = &base.FileInfo{
|
||||
Name: filepath.Base(file.DisplayPath()),
|
||||
Path: util.Dir(file.Path()),
|
||||
Path: util.Dir(path.Join(f.torrent.Info().Name, file.Path())),
|
||||
Size: file.Length(),
|
||||
}
|
||||
res.Size += file.Length()
|
||||
@@ -101,7 +103,7 @@ func (f *Fetcher) Create(opts *base.Options) (err error) {
|
||||
}
|
||||
}
|
||||
if opts.Path != "" {
|
||||
f.torrentPaths[f.meta.Res.Hash] = f.meta.Opts.Path
|
||||
f.torrentPaths[f.meta.Res.Hash] = path.Join(f.meta.Opts.Path, f.meta.Res.RootDir)
|
||||
}
|
||||
|
||||
f.progress = make(fetcher.Progress, len(f.meta.Opts.SelectFiles))
|
||||
|
||||
@@ -33,6 +33,7 @@ func doResolve(t *testing.T, fetcher fetcher.Fetcher) {
|
||||
Files: []*base.FileInfo{
|
||||
{
|
||||
Name: "ubuntu-22.04-live-server-amd64.iso",
|
||||
Path: "ubuntu-22.04-live-server-amd64.iso",
|
||||
Size: 1466714112,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/monkeyWie/gopeed/internal/fetcher"
|
||||
"github.com/monkeyWie/gopeed/pkg/base"
|
||||
fhttp "github.com/monkeyWie/gopeed/pkg/protocol/http"
|
||||
"github.com/monkeyWie/gopeed/pkg/util"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"io"
|
||||
"mime"
|
||||
@@ -245,7 +244,7 @@ func (f *Fetcher) Wait() (err error) {
|
||||
}
|
||||
|
||||
func (f *Fetcher) filepath() string {
|
||||
return util.Filepath(f.meta.Opts.Path, f.meta.Res.Files[0].Name, f.meta.Opts.Name)
|
||||
return f.meta.Filepath(f.meta.Res.Files[0])
|
||||
}
|
||||
|
||||
func (f *Fetcher) fetch() {
|
||||
|
||||
Reference in new issue
Block a user