Added better archive functionalty (backend side atm)
Code refactoring
This commit is contained in:
42
server/archiver/archiver.go
Normal file
42
server/archiver/archiver.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package archiver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
|
||||
evbus "github.com/asaskevich/EventBus"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/v3/server/archive"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/v3/server/config"
|
||||
)
|
||||
|
||||
const QueueName = "process:archive"
|
||||
|
||||
var (
|
||||
eventBus = evbus.New()
|
||||
archiveService archive.Service
|
||||
)
|
||||
|
||||
type Message = archive.Entity
|
||||
|
||||
func Register(db *sql.DB) {
|
||||
_, s := archive.Container(db)
|
||||
archiveService = s
|
||||
}
|
||||
|
||||
func init() {
|
||||
eventBus.Subscribe(QueueName, func(m *Message) {
|
||||
slog.Info(
|
||||
"archiving completed download",
|
||||
slog.String("title", m.Title),
|
||||
slog.String("source", m.Source),
|
||||
)
|
||||
archiveService.Archive(context.Background(), m)
|
||||
})
|
||||
}
|
||||
|
||||
func Publish(m *Message) {
|
||||
if config.Instance().AutoArchive {
|
||||
eventBus.Publish(QueueName, m)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user