chore: Refactor code to use SourceUpdater struct for managing sources

This commit is contained in:
royalcat 2024-05-18 10:24:14 +03:00
parent fa1fdcfc63
commit 99cdd5471e
12 changed files with 328 additions and 263 deletions
src/delivery/graphql/resolver

View file

@ -93,9 +93,7 @@ func (r *mutationResolver) DownloadTorrent(ctx context.Context, infohash string,
// UploadFile is the resolver for the uploadFile field.
func (r *mutationResolver) UploadFile(ctx context.Context, dir string, file graphql.Upload) (bool, error) {
dir = pathlib.Join(r.Service.SourceDir, dir)
dirInfo, err := os.Stat(dir)
dirInfo, err := r.SourceFS.Stat(dir)
if err != nil {
return false, err
}
@ -105,7 +103,7 @@ func (r *mutationResolver) UploadFile(ctx context.Context, dir string, file grap
}
filename := pathlib.Join(dir, file.Filename)
target, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, os.ModePerm)
target, err := r.SourceFS.OpenFile(filename, os.O_CREATE|os.O_WRONLY, os.ModePerm)
defer target.Close()
if err != nil {
return false, err

View file

@ -3,6 +3,7 @@ package resolver
import (
"git.kmsign.ru/royalcat/tstor/src/host/service"
"git.kmsign.ru/royalcat/tstor/src/host/vfs"
"github.com/go-git/go-billy/v5"
)
// This file will not be regenerated automatically.
@ -10,6 +11,7 @@ import (
// It serves as dependency injection for your app, add any dependencies you require here.
type Resolver struct {
Service *service.Service
VFS vfs.Filesystem
Service *service.Service
VFS vfs.Filesystem
SourceFS billy.Filesystem
}