diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-04 18:38:10 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-04 18:40:02 +0200 |
commit | 311ab744fe1bf278b18c25892497271988399e9a (patch) | |
tree | 89f956f521000ac0d22f815e91cab4cf00a8b70f /pkg/service/filesystem.go | |
parent | c2d666b43477ea7042b574ad940c508216cb0e83 (diff) | |
download | lens-311ab744fe1bf278b18c25892497271988399e9a.tar.gz lens-311ab744fe1bf278b18c25892497271988399e9a.tar.bz2 lens-311ab744fe1bf278b18c25892497271988399e9a.zip |
feat: Add user based files
Now files follow user path configuration
Diffstat (limited to 'pkg/service/filesystem.go')
-rw-r--r-- | pkg/service/filesystem.go | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/pkg/service/filesystem.go b/pkg/service/filesystem.go index 3516ce2..cdfd106 100644 --- a/pkg/service/filesystem.go +++ b/pkg/service/filesystem.go @@ -1,17 +1,20 @@ package service import ( + "context" "io/fs" "net/url" "path" "strings" "git.sr.ht/~gabrielgio/img/pkg/database/repository" + "git.sr.ht/~gabrielgio/img/pkg/list" ) type ( FileSystemController struct { - repository repository.FileSystemRepository + fsRepository repository.FileSystemRepository + userRepository repository.UserRepository } DirectoryParam struct { @@ -30,9 +33,13 @@ type ( } ) -func NewFileSystemController(repository repository.FileSystemRepository) *FileSystemController { +func NewFileSystemController( + fsRepository repository.FileSystemRepository, + userRepository repository.UserRepository, +) *FileSystemController { return &FileSystemController{ - repository: repository, + fsRepository: fsRepository, + userRepository: userRepository, } } @@ -63,26 +70,30 @@ func getHistory(filepath string) []*DirectoryParam { return result } -func (self *FileSystemController) GetPage(filepath string) (*Page, error) { +func (self *FileSystemController) GetPage(ctx context.Context, userID uint, filepath string) (*Page, error) { + userPath, err := self.userRepository.GetPathFromUserID(ctx, userID) + if err != nil { + return nil, err + } decodedPath, err := url.QueryUnescape(filepath) if err != nil { return nil, err } - files, err := self.repository.List(decodedPath) + fullPath := path.Join(userPath, decodedPath) + files, err := self.fsRepository.List(fullPath) if err != nil { return nil, err } - params := make([]*FileParam, 0, len(files)) - for _, info := range files { - fullPath := path.Join(decodedPath, info.Name()) + params := list.Map(files, func(info fs.FileInfo) *FileParam { + fullPath := path.Join(fullPath, info.Name()) scapedFullPath := url.QueryEscape(fullPath) - params = append(params, &FileParam{ + return &FileParam{ Info: info, UrlEncodedPath: scapedFullPath, - }) - } + } + }) return &Page{ Files: params, |