aboutsummaryrefslogtreecommitdiff
path: root/pkg/service/filesystem.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-07-04 18:38:10 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-07-04 18:40:02 +0200
commit311ab744fe1bf278b18c25892497271988399e9a (patch)
tree89f956f521000ac0d22f815e91cab4cf00a8b70f /pkg/service/filesystem.go
parentc2d666b43477ea7042b574ad940c508216cb0e83 (diff)
downloadlens-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.go33
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,