Handle file rescan (#2951)

* Fire handlers when file updated or moved
* Create galleries as needed
* Clean empty galleries
* Handle cleaning zip folders when path changed
* Fix gallery association on duplicate images
* Re-create missing folder-based galleries
This commit is contained in:
WithoutPants
2022-09-28 16:08:00 +10:00
committed by GitHub
parent 00820a8789
commit dce90a3ed9
13 changed files with 439 additions and 106 deletions

View File

@@ -13,6 +13,7 @@ const (
type hookManager struct {
postCommitHooks []TxnFunc
postRollbackHooks []TxnFunc
postCompleteHooks []TxnFunc
}
func (m *hookManager) register(ctx context.Context) context.Context {
@@ -27,20 +28,26 @@ func hookManagerCtx(ctx context.Context) *hookManager {
return m
}
func executePostCommitHooks(ctx context.Context) {
m := hookManagerCtx(ctx)
for _, h := range m.postCommitHooks {
func executeHooks(ctx context.Context, hooks []TxnFunc) {
for _, h := range hooks {
// ignore errors
_ = h(ctx)
}
}
func executePostCommitHooks(ctx context.Context) {
m := hookManagerCtx(ctx)
executeHooks(ctx, m.postCommitHooks)
}
func executePostRollbackHooks(ctx context.Context) {
m := hookManagerCtx(ctx)
for _, h := range m.postRollbackHooks {
// ignore errors
_ = h(ctx)
}
executeHooks(ctx, m.postRollbackHooks)
}
func executePostCompleteHooks(ctx context.Context) {
m := hookManagerCtx(ctx)
executeHooks(ctx, m.postCompleteHooks)
}
func AddPostCommitHook(ctx context.Context, hook TxnFunc) {
@@ -52,3 +59,8 @@ func AddPostRollbackHook(ctx context.Context, hook TxnFunc) {
m := hookManagerCtx(ctx)
m.postRollbackHooks = append(m.postRollbackHooks, hook)
}
func AddPostCompleteHook(ctx context.Context, hook TxnFunc) {
m := hookManagerCtx(ctx)
m.postCompleteHooks = append(m.postCompleteHooks, hook)
}