lens @ 69d71c2a495d9cce1984ba2ffddf1d98622b01fe

feat: Move to user path media

Now media also base on user folder to fetch its media.
diff --git a/Makefile b/Makefile
index b18993b3a1d074320216b62d9f8344ba839d51fa..f1c2095dd81cc0b1c7fbd2d258fb56129635f3e9 100644
--- a/Makefile
+++ b/Makefile
@@ -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 b81b2916115977c566ef4ae741e144368e9e933b..8f163dfd6e4f2471f99d51b530cd816a0f184ebf 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -62,6 +62,10 @@ 	if err = sql.Migrate(db); err != nil {
 		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 @@ 	for _, v := range []view.View{
 		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 6ab4ee673adc2f12d4227113c9ef4822b5d34d0b..6f5b39b5326491e889cca59690c8a1fe00ff4fee 100644
--- a/pkg/database/repository/media.go
+++ b/pkg/database/repository/media.go
@@ -41,6 +41,7 @@
 	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 b8203f382fb83a92aa9d8447afda5918188166af..e5ba517408453841bee462e8bc432879423564f4 100644
--- a/pkg/database/sql/media.go
+++ b/pkg/database/sql/media.go
@@ -139,6 +139,7 @@ 		WithContext(ctx).
 		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 @@ 	result := r.db.
 		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 @@ 	result := r.db.
 		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 10e220242ecdd4124c057cca253bacb095bcc7a9..8999f07e61484609eab2b648107f23643c545284 100644
--- a/pkg/fileop/file.go
+++ b/pkg/fileop/file.go
@@ -12,7 +12,8 @@ 	return hex.EncodeToString(hash[:])
 }
 
 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 cdfd106746896e4f7ad9cca777b4595346443258..2e4b51099efa02ec811011baa731bd4f4ae2795e 100644
--- a/pkg/service/filesystem.go
+++ b/pkg/service/filesystem.go
@@ -87,7 +87,7 @@ 		return nil, err
 	}
 
 	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 bea515d9e6657d47e21c4136a57a94995734b0f8..6d380e25a294884a3bc8de9e9c090b1bd33bb31a 100644
--- a/pkg/view/media.go
+++ b/pkg/view/media.go
@@ -13,6 +13,7 @@
 type (
 	MediaView struct {
 		mediaRepository repository.MediaRepository
+		userRepository  repository.UserRepository
 	}
 
 	Page struct {
@@ -51,14 +52,26 @@ 		Size: size,
 	}
 }
 
-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 02fd4dd51d4c215edb4a03d2f2d6ce05ef371afb..8245eadd895f1910ff2482d1af5c68be8db9658f 100644
--- a/pkg/worker/scanner/thumbnail_scanner.go
+++ b/pkg/worker/scanner/thumbnail_scanner.go
@@ -35,6 +35,12 @@ 		Size: 100,
 	})
 }
 
+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:]