diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2023-12-01 00:26:06 +0100 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2023-12-01 00:26:06 +0100 |
commit | 14e5580efd51c7b9e70d304715e512a2ea2a1b21 (patch) | |
tree | 8d118d355f631fd9225354d8dc65b4b225946489 /pkg/service | |
parent | c3ea735c0f03a0827a8e753a5b5adf6e31f4c925 (diff) | |
download | lens-14e5580efd51c7b9e70d304715e512a2ea2a1b21.tar.gz lens-14e5580efd51c7b9e70d304715e512a2ea2a1b21.tar.bz2 lens-14e5580efd51c7b9e70d304715e512a2ea2a1b21.zip |
feat: Add option to download file
Diffstat (limited to 'pkg/service')
-rw-r--r-- | pkg/service/filesystem.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/pkg/service/filesystem.go b/pkg/service/filesystem.go index b4479ea..1364fd8 100644 --- a/pkg/service/filesystem.go +++ b/pkg/service/filesystem.go @@ -85,24 +85,32 @@ func getHistory(filepath string) []*DirectoryParam { return result } -func (self *FileSystemController) GetPage(ctx context.Context, userID uint, filepath string) (*Page, error) { - userPath, err := self.userRepository.GetPathFromUserID(ctx, userID) +func (f *FileSystemController) GetFullpath(ctx context.Context, userID uint, filepath string) (string, error) { + userPath, err := f.userRepository.GetPathFromUserID(ctx, userID) if err != nil { - return nil, err + return "", err } - decodedPath, err := url.QueryUnescape(filepath) + + return path.Join(userPath, filepath), nil +} + +func (f *FileSystemController) IsFile(ctx context.Context, fullPath string) (bool, error) { + inf, err := f.fsRepository.Stat(fullPath) if err != nil { - return nil, err + return false, err } - fullPath := path.Join(userPath, decodedPath) - files, err := self.fsRepository.List(fullPath) + return !inf.IsDir(), nil +} + +func (f *FileSystemController) GetPage(ctx context.Context, filename string, fullPath string) (*Page, error) { + + files, err := f.fsRepository.List(fullPath) if err != nil { return nil, err } - params := list.Map(files, func(info fs.FileInfo) *FileParam { - fullPath := path.Join(decodedPath, info.Name()) + fullPath := path.Join(filename, info.Name()) scapedFullPath := url.QueryEscape(fullPath) return &FileParam{ Info: info, @@ -112,6 +120,6 @@ func (self *FileSystemController) GetPage(ctx context.Context, userID uint, file return &Page{ Files: params, - History: getHistory(decodedPath), + History: getHistory(filename), }, nil } |