diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-18 21:41:53 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-18 21:41:53 +0200 |
commit | 69d71c2a495d9cce1984ba2ffddf1d98622b01fe (patch) | |
tree | 3abd105a970fe773c0b19cb0c4f974688001e5e0 | |
parent | 05a8dbf46792adfef007a0ffbcb654026db036fa (diff) | |
download | lens-69d71c2a495d9cce1984ba2ffddf1d98622b01fe.tar.gz lens-69d71c2a495d9cce1984ba2ffddf1d98622b01fe.tar.bz2 lens-69d71c2a495d9cce1984ba2ffddf1d98622b01fe.zip |
feat: Move to user path media
Now media also base on user folder to fetch its media.
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cmd/server/main.go | 6 | ||||
-rw-r--r-- | pkg/database/repository/media.go | 1 | ||||
-rw-r--r-- | pkg/database/sql/media.go | 5 | ||||
-rw-r--r-- | pkg/fileop/file.go | 3 | ||||
-rw-r--r-- | pkg/service/filesystem.go | 2 | ||||
-rw-r--r-- | pkg/view/media.go | 15 | ||||
-rw-r--r-- | pkg/worker/scanner/thumbnail_scanner.go | 6 |
8 files changed, 33 insertions, 8 deletions
@@ -21,8 +21,7 @@ run: sass $(GO_RUN) $(SERVER) \ --log-level error \ --aes-key=6368616e676520746869732070617373 \ - --cache-path=${HOME}/.thumb \ - --root=${HOME} + --cache-path=${HOME}/.thumb sass: @mkdir -p static diff --git a/cmd/server/main.go b/cmd/server/main.go index b81b291..8f163df 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -62,6 +62,10 @@ func main() { panic("failed to migrate database: " + err.Error()) } + if *dbType == "sqlite" { + *schedulerCount = 1 + } + hexKey, err := hex.DecodeString(*key) if err != nil { panic("failed to decode key database: " + err.Error()) @@ -104,7 +108,7 @@ func main() { view.NewAuthView(userController), view.NewFileSystemView(*fileSystemController, settingsRepository), view.NewSettingsView(settingsRepository, userRepository), - view.NewMediaView(mediaRepository), + view.NewMediaView(mediaRepository, userRepository), } { v.SetMyselfIn(extRouter) } diff --git a/pkg/database/repository/media.go b/pkg/database/repository/media.go index 6ab4ee6..6f5b39b 100644 --- a/pkg/database/repository/media.go +++ b/pkg/database/repository/media.go @@ -41,6 +41,7 @@ type ( Pagination struct { Page int Size int + Path string } CreateMedia struct { diff --git a/pkg/database/sql/media.go b/pkg/database/sql/media.go index b8203f3..e5ba517 100644 --- a/pkg/database/sql/media.go +++ b/pkg/database/sql/media.go @@ -139,6 +139,7 @@ func (self *MediaRepository) List(ctx context.Context, pagination *repository.Pa Model(&Media{}). Offset(pagination.Page * pagination.Size). Limit(pagination.Size). + Where("path like '" + pagination.Path + "%'"). Order("created_at DESC"). Find(&medias) @@ -257,7 +258,7 @@ func (r *MediaRepository) ListEmptyEXIF(ctx context.Context, pagination *reposit WithContext(ctx). Model(&Media{}). Joins("left join media_exifs on media.id = media_exifs.media_id"). - Where("media_exifs.media_id IS NULL"). + Where("media_exifs.media_id IS NULL AND media.path like '" + pagination.Path + "%'"). Offset(pagination.Page * pagination.Size). Limit(pagination.Size). Order("media.created_at DESC"). @@ -280,7 +281,7 @@ func (r *MediaRepository) ListEmptyThumbnail(ctx context.Context, pagination *re WithContext(ctx). Model(&Media{}). Joins("left join media_thumbnails on media.id = media_thumbnails.media_id"). - Where("media_thumbnails.media_id IS NULL"). + Where("media_thumbnails.media_id IS NULL AND media.path like '" + pagination.Path + "%'"). Offset(pagination.Page * pagination.Size). Limit(pagination.Size). Order("media.created_at DESC"). diff --git a/pkg/fileop/file.go b/pkg/fileop/file.go index 10e2202..8999f07 100644 --- a/pkg/fileop/file.go +++ b/pkg/fileop/file.go @@ -12,7 +12,8 @@ func GetHashFromPath(path string) string { } func IsMimeTypeSupported(mimetype string) bool { - if mimetype == "image/svg+xml" { + if mimetype == "image/svg+xml" || + mimetype == "video/mp2t" { return false } return strings.HasPrefix(mimetype, "video") || diff --git a/pkg/service/filesystem.go b/pkg/service/filesystem.go index cdfd106..2e4b510 100644 --- a/pkg/service/filesystem.go +++ b/pkg/service/filesystem.go @@ -87,7 +87,7 @@ func (self *FileSystemController) GetPage(ctx context.Context, userID uint, file } params := list.Map(files, func(info fs.FileInfo) *FileParam { - fullPath := path.Join(fullPath, info.Name()) + fullPath := path.Join(decodedPath, info.Name()) scapedFullPath := url.QueryEscape(fullPath) return &FileParam{ Info: info, diff --git a/pkg/view/media.go b/pkg/view/media.go index bea515d..6d380e2 100644 --- a/pkg/view/media.go +++ b/pkg/view/media.go @@ -13,6 +13,7 @@ import ( type ( MediaView struct { mediaRepository repository.MediaRepository + userRepository repository.UserRepository } Page struct { @@ -51,14 +52,26 @@ func getPagination(ctx *fasthttp.RequestCtx) *repository.Pagination { } } -func NewMediaView(mediaRepository repository.MediaRepository) *MediaView { +func NewMediaView( + mediaRepository repository.MediaRepository, + userRepository repository.UserRepository, +) *MediaView { return &MediaView{ mediaRepository: mediaRepository, + userRepository: userRepository, } } func (self *MediaView) Index(ctx *fasthttp.RequestCtx) error { p := getPagination(ctx) + token := ext.GetTokenFromCtx(ctx) + + userPath, err := self.userRepository.GetPathFromUserID(ctx, token.UserID) + if err != nil { + return err + } + + p.Path = userPath medias, err := self.mediaRepository.List(ctx, p) if err != nil { return err diff --git a/pkg/worker/scanner/thumbnail_scanner.go b/pkg/worker/scanner/thumbnail_scanner.go index 02fd4dd..8245ead 100644 --- a/pkg/worker/scanner/thumbnail_scanner.go +++ b/pkg/worker/scanner/thumbnail_scanner.go @@ -35,6 +35,12 @@ func (t *ThumbnailScanner) Query(ctx context.Context) ([]*repository.Media, erro }) } +func (t *ThumbnailScanner) OnFail(ctx context.Context, media *repository.Media, err error) { + _ = t.repository.CreateThumbnail(ctx, media.ID, &repository.MediaThumbnail{ + Path: "", + }) +} + func (t *ThumbnailScanner) Process(ctx context.Context, media *repository.Media) error { split := media.PathHash[:2] filename := media.PathHash[2:] |