ultisuite-backend/internal/api/drive/automation_hooks.go
R3D347HR4Y 082cac36b2 feat(automation): dispatch rules/webhooks on mail, drive, contacts
Wire automation dispatcher to IMAP sync, drive mutations, and contact CRUD.
Add webhook event_types and mail/drive/contacts scope filters (migration 30).
2026-06-07 15:51:47 +02:00

41 lines
1.3 KiB
Go

package drive
import (
"context"
"path"
"github.com/ultisuite/ulti-backend/internal/automation"
"github.com/ultisuite/ulti-backend/internal/mail/rules"
"github.com/ultisuite/ulti-backend/internal/nextcloud"
)
func (s *Service) SetAutomation(d driveAutomation) {
s.automation = d
}
func (s *Service) afterDriveFileEvent(ctx context.Context, externalUserID string, trigger rules.TriggerType, filePath string, isFolder bool) {
normalized := nextcloud.NormalizeClientPath(filePath)
s.notifyFileChanged(externalUserID, normalized)
if s.automation == nil {
return
}
s.automation.OnDriveEvent(ctx, externalUserID, trigger, automation.DrivePayloadFromPath(normalized, isFolder))
}
func (s *Service) afterDriveShareEvent(ctx context.Context, externalUserID string, filePath string) {
normalized := nextcloud.NormalizeClientPath(filePath)
s.notifyShareUpdated(externalUserID, normalized)
if s.automation == nil {
return
}
s.automation.OnDriveEvent(ctx, externalUserID, rules.TriggerDriveShareUpdated, automation.DrivePayloadFromPath(normalized, false))
}
func renamedPath(oldPath, newName string) string {
dir := path.Dir(nextcloud.NormalizeClientPath(oldPath))
if dir == "." || dir == "" {
dir = "/"
}
return nextcloud.NormalizeClientPath(path.Join(dir, newName))
}