mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Sharing: Instantly trigger upload #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/query"
|
"github.com/photoprism/photoprism/internal/query"
|
||||||
|
"github.com/photoprism/photoprism/internal/workers"
|
||||||
"github.com/photoprism/photoprism/pkg/txt"
|
"github.com/photoprism/photoprism/pkg/txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -144,6 +145,8 @@ func ShareWithAccount(router *gin.RouterGroup, conf *config.Config) {
|
|||||||
fileShare.FirstOrCreate(conf.Db())
|
fileShare.FirstOrCreate(conf.Db())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workers.StartShare(conf)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, files)
|
c.JSON(http.StatusOK, files)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func (s *Share) Start() (err error) {
|
|||||||
file.Errors++
|
file.Errors++
|
||||||
file.Error = err.Error()
|
file.Error = err.Error()
|
||||||
} else {
|
} else {
|
||||||
|
log.Infof("share: uploaded %s to %s", file.RemoteName, a.AccName)
|
||||||
file.Errors = 0
|
file.Errors = 0
|
||||||
file.Error = ""
|
file.Error = ""
|
||||||
file.Status = entity.FileShareShared
|
file.Status = entity.FileShareShared
|
||||||
@@ -156,6 +157,7 @@ func (s *Share) Start() (err error) {
|
|||||||
file.Errors++
|
file.Errors++
|
||||||
file.Error = err.Error()
|
file.Error = err.Error()
|
||||||
} else {
|
} else {
|
||||||
|
log.Infof("share: removed %s from %s", file.RemoteName, a.AccName)
|
||||||
file.Errors = 0
|
file.Errors = 0
|
||||||
file.Error = ""
|
file.Error = ""
|
||||||
file.Status = entity.FileShareRemoved
|
file.Status = entity.FileShareRemoved
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var log = event.Log
|
|||||||
var stop = make(chan bool, 1)
|
var stop = make(chan bool, 1)
|
||||||
|
|
||||||
func Start(conf *config.Config) {
|
func Start(conf *config.Config) {
|
||||||
ticker := time.NewTicker(5 * time.Minute) // TODO
|
ticker := time.NewTicker(15 * time.Minute)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@@ -24,30 +24,35 @@ func Start(conf *config.Config) {
|
|||||||
mutex.Sync.Cancel()
|
mutex.Sync.Cancel()
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if !mutex.Share.Busy() {
|
StartShare(conf)
|
||||||
go func() {
|
StartSync(conf)
|
||||||
// Start
|
|
||||||
s := NewShare(conf)
|
|
||||||
if err := s.Start(); err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
if !mutex.Sync.Busy() {
|
|
||||||
go func() {
|
|
||||||
// Start
|
|
||||||
s := NewSync(conf)
|
|
||||||
if err := s.Start(); err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartShare(conf *config.Config) {
|
||||||
|
if !mutex.Share.Busy() {
|
||||||
|
go func() {
|
||||||
|
s := NewShare(conf)
|
||||||
|
if err := s.Start(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StartSync(conf *config.Config) {
|
||||||
|
if !mutex.Sync.Busy() {
|
||||||
|
go func() {
|
||||||
|
s := NewSync(conf)
|
||||||
|
if err := s.Start(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Stop() {
|
func Stop() {
|
||||||
stop <- true
|
stop <- true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user