-
Notifications
You must be signed in to change notification settings - Fork 2
/
media_app.go
79 lines (62 loc) · 2.38 KB
/
media_app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright © 2014-2023 Thomas Rabaix <thomas.rabaix@gmail.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package media
import (
"net/http"
pq "github.com/lib/pq"
"github.com/rande/goapp"
"github.com/rande/gonode/core/config"
"github.com/rande/gonode/core/vault"
"github.com/rande/gonode/modules/base"
log "github.com/sirupsen/logrus"
)
func Configure(l *goapp.Lifecycle, conf *config.Config) {
l.Register(func(app *goapp.App) error {
app.Set("gonode.listener.youtube", func(app *goapp.App) interface{} {
return &YoutubeListener{
HttpClient: app.Get("gonode.http_client").(*http.Client),
}
})
app.Set("gonode.listener.file_downloader", func(app *goapp.App) interface{} {
return &ImageDownloadListener{
Vault: app.Get("gonode.vault.fs").(*vault.Vault),
HttpClient: app.Get("gonode.http_client").(*http.Client),
Logger: app.Get("logger").(*log.Logger),
}
})
return nil
})
l.Prepare(func(app *goapp.App) error {
c := app.Get("gonode.handler_collection").(base.HandlerCollection)
c.Add("media.image", &ImageHandler{
Vault: app.Get("gonode.vault.fs").(*vault.Vault),
Logger: app.Get("logger").(*log.Logger),
})
c.Add("media.youtube", &YoutubeHandler{})
cv := app.Get("gonode.view_handler_collection").(base.ViewHandlerCollection)
cv.Add("media.image", &MediaViewHandler{
Vault: app.Get("gonode.vault.fs").(*vault.Vault),
MaxWidth: conf.Media.Image.MaxWidth,
AllowedWidths: conf.Media.Image.AllowedWidths,
})
// need to find a way to trigger the handler registration
sub := app.Get("gonode.postgres.subscriber").(*base.Subscriber)
sub.ListenMessage("media_youtube_update", func(app *goapp.App) base.SubscriberHander {
manager := app.Get("gonode.manager").(*base.PgNodeManager)
listener := app.Get("gonode.listener.youtube").(*YoutubeListener)
return func(notification *pq.Notification) (int, error) {
return listener.Handle(notification, manager)
}
}(app))
sub.ListenMessage("media_file_download", func(app *goapp.App) base.SubscriberHander {
manager := app.Get("gonode.manager").(*base.PgNodeManager)
listener := app.Get("gonode.listener.file_downloader").(*ImageDownloadListener)
return func(notification *pq.Notification) (int, error) {
return listener.Handle(notification, manager)
}
}(app))
return nil
})
}