aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/server/main.go2
-rw-r--r--pkg/database/repository/settings.go5
-rw-r--r--pkg/database/sql/settings.go11
-rw-r--r--pkg/service/auth_test.go1
-rw-r--r--pkg/view/media.go17
-rw-r--r--pkg/view/settings.go10
-rw-r--r--templates/media.qtpl14
-rw-r--r--templates/settings.qtpl8
8 files changed, 49 insertions, 19 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go
index b940145..c7f9019 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -108,7 +108,7 @@ func main() {
view.NewAuthView(userController),
view.NewFileSystemView(*fileSystemController, settingsRepository),
view.NewSettingsView(settingsRepository, userRepository),
- view.NewMediaView(mediaRepository, userRepository),
+ view.NewMediaView(mediaRepository, userRepository, settingsRepository),
} {
v.SetMyselfIn(extRouter)
}
diff --git a/pkg/database/repository/settings.go b/pkg/database/repository/settings.go
index 6ed1eb6..c3d8fbb 100644
--- a/pkg/database/repository/settings.go
+++ b/pkg/database/repository/settings.go
@@ -4,8 +4,9 @@ import "context"
type (
Settings struct {
- ShowMode bool
- ShowOwner bool
+ ShowMode bool
+ ShowOwner bool
+ PreloadVideoMetadata bool
}
SettingsRepository interface {
diff --git a/pkg/database/sql/settings.go b/pkg/database/sql/settings.go
index 4e73878..3f4ad08 100644
--- a/pkg/database/sql/settings.go
+++ b/pkg/database/sql/settings.go
@@ -11,8 +11,9 @@ import (
type (
Settings struct {
gorm.Model
- ShowMode bool
- ShowOwner bool
+ ShowMode bool
+ ShowOwner bool
+ PreloadVideoMetadata bool
}
SettingsRepository struct {
@@ -51,6 +52,7 @@ func (self *SettingsRepository) Save(ctx context.Context, toSaveSettings *reposi
s.ShowMode = toSaveSettings.ShowMode
s.ShowOwner = toSaveSettings.ShowOwner
+ s.PreloadVideoMetadata = toSaveSettings.PreloadVideoMetadata
result := db.Save(s)
return result.Error
@@ -63,7 +65,8 @@ func (self *SettingsRepository) Load(ctx context.Context) (*repository.Settings,
}
return &repository.Settings{
- ShowMode: s.ShowMode,
- ShowOwner: s.ShowOwner,
+ ShowMode: s.ShowMode,
+ ShowOwner: s.ShowOwner,
+ PreloadVideoMetadata: s.PreloadVideoMetadata,
}, nil
}
diff --git a/pkg/service/auth_test.go b/pkg/service/auth_test.go
index 7083d0c..179ded7 100644
--- a/pkg/service/auth_test.go
+++ b/pkg/service/auth_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
- "git.sr.ht/~gabrielgio/img/pkg/ext"
"git.sr.ht/~gabrielgio/img/pkg/testkit"
)
diff --git a/pkg/view/media.go b/pkg/view/media.go
index e247940..6e34fd6 100644
--- a/pkg/view/media.go
+++ b/pkg/view/media.go
@@ -12,8 +12,9 @@ import (
type (
MediaView struct {
- mediaRepository repository.MediaRepository
- userRepository repository.UserRepository
+ mediaRepository repository.MediaRepository
+ userRepository repository.UserRepository
+ settingsRepository repository.SettingsRepository
}
)
@@ -50,10 +51,12 @@ func getPagination(ctx *fasthttp.RequestCtx) *repository.Pagination {
func NewMediaView(
mediaRepository repository.MediaRepository,
userRepository repository.UserRepository,
+ settingsRepository repository.SettingsRepository,
) *MediaView {
return &MediaView{
- mediaRepository: mediaRepository,
- userRepository: userRepository,
+ mediaRepository: mediaRepository,
+ userRepository: userRepository,
+ settingsRepository: settingsRepository,
}
}
@@ -72,12 +75,18 @@ func (self *MediaView) Index(ctx *fasthttp.RequestCtx) error {
return err
}
+ settings, err := self.settingsRepository.Load(ctx)
+ if err != nil {
+ return err
+ }
+
page := &templates.MediaPage{
Medias: medias,
Next: &repository.Pagination{
Size: p.Size,
Page: p.Page + 1,
},
+ Settings: settings,
}
templates.WritePageTemplate(ctx, page)
diff --git a/pkg/view/settings.go b/pkg/view/settings.go
index bee3dc2..ffce86b 100644
--- a/pkg/view/settings.go
+++ b/pkg/view/settings.go
@@ -47,13 +47,15 @@ func (self *SettingsView) Index(ctx *fasthttp.RequestCtx) error {
func (self *SettingsView) Save(ctx *fasthttp.RequestCtx) error {
var (
- showMode = string(ctx.FormValue("showMode")) == "on"
- showOwner = string(ctx.FormValue("showOwner")) == "on"
+ showMode = string(ctx.FormValue("showMode")) == "on"
+ showOwner = string(ctx.FormValue("showOwner")) == "on"
+ preloadVideoMetadata = string(ctx.FormValue("preloadVideoMetadata")) == "on"
)
err := self.settingsRepository.Save(ctx, &repository.Settings{
- ShowMode: showMode,
- ShowOwner: showOwner,
+ ShowMode: showMode,
+ ShowOwner: showOwner,
+ PreloadVideoMetadata: preloadVideoMetadata,
})
if err != nil {
return err
diff --git a/templates/media.qtpl b/templates/media.qtpl
index 18eac0d..6217899 100644
--- a/templates/media.qtpl
+++ b/templates/media.qtpl
@@ -2,8 +2,16 @@
{% code
type MediaPage struct {
- Medias []*repository.Media
- Next *repository.Pagination
+ Medias []*repository.Media
+ Next *repository.Pagination
+ Settings *repository.Settings
+}
+
+func (m *MediaPage) PreloadAttr() string {
+ if m.Settings.PreloadVideoMetadata {
+ return "metadata"
+ }
+ return "none"
}
%}
@@ -14,7 +22,7 @@ type MediaPage struct {
{% for _, media := range p.Medias %}
<div class="card-image">
{% if media.IsVideo() %}
- <video class="image is-fit" controls muted="true" poster="/media/thumbnail?path_hash={%s media.PathHash %}" preload="metadata">
+ <video class="image is-fit" controls muted="true" poster="/media/thumbnail?path_hash={%s media.PathHash %}" preload="{%s p.PreloadAttr() %}">
<source src="/media/image?path_hash={%s media.PathHash %}" type="{%s media.MIMEType %}">
</video>
{% else %}
diff --git a/templates/settings.qtpl b/templates/settings.qtpl
index 509cddd..6eee1ab 100644
--- a/templates/settings.qtpl
+++ b/templates/settings.qtpl
@@ -30,6 +30,14 @@ type SettingsPage struct {
</div>
</div>
<div class="field">
+ <div class="control">
+ <label class="checkbox">
+ <input type="checkbox" id="preloadVideoMetadata" name="preloadVideoMetadata" {% if p.Settings.PreloadVideoMetadata %}checked{% endif %}>
+ Preload video metadata
+ </label>
+ </div>
+ </div>
+ <div class="field">
<input class="button" value="save" type="submit">
</div>
</form>