photoprism/internal/event
2026-06-24 17:20:30 +02:00
..
audit.go Audit: Add trace helper for quiet session cleanup logs 2026-03-29 14:21:18 +02:00
buffer.go Logs: Prevent feedback loops by omitting repeated messages #2335 2022-05-20 11:31:39 +02:00
buffer_test.go Logs: Prevent feedback loops by omitting repeated messages #2335 2022-05-20 11:31:39 +02:00
event.go Links: Use canonical trailing-slash form for website URLs 2026-06-24 17:20:30 +02:00
format.go Go: Apply go fix modernizations across backend packages 2026-02-20 03:54:33 +01:00
format_test.go Logs: Refactor message formatting in event package 2025-03-26 12:58:51 +01:00
hub.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
hub_test.go Auth: Session and ACL enhancements #98 #1746 2022-09-28 09:01:17 +02:00
init.go Config: Set SystemLog level based on application log level #5167 2025-10-07 21:30:19 +02:00
log.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
log_test.go Backend: Format go imports 2020-11-21 18:08:41 +01:00
log_writer.go Logging: Add output writer wrapper so the default logger can use Logrus 2022-12-23 01:35:59 +01:00
log_writer_test.go Logging: Add output writer wrapper so the default logger can use Logrus 2022-12-23 01:35:59 +01:00
logger.go Go: Apply go fix modernizations across backend packages 2026-02-20 03:54:33 +01:00
login.go Account: Refactor access token API and request forms #808 #4114 2024-04-05 14:46:11 +02:00
panic.go Event: Use first event segment as the system log prefix 2026-06-03 14:58:01 +00:00
panic_test.go Backend: Report recovered panics via SystemLog, not the DB logger #5637 2026-06-03 08:29:40 +00:00
publish.go UX: Name message fields messageId/messageParams in i18n payloads #5682 2026-06-23 12:22:30 +00:00
publish_entities.go Events: Refactor entity change notifications for sharing features #1307 2026-06-11 15:40:57 +00:00
publish_entities_test.go Events: Refactor entity change notifications for sharing features #1307 2026-06-11 15:40:57 +00:00
publish_test.go UX: Name message fields messageId/messageParams in i18n payloads #5682 2026-06-23 12:22:30 +00:00
README.md UX: Name message fields messageId/messageParams in i18n payloads #5682 2026-06-23 12:22:30 +00:00
system.go Event: Use first event segment as the system log prefix 2026-06-03 14:58:01 +00:00
system_test.go Event: Use first event segment as the system log prefix 2026-06-03 14:58:01 +00:00
time.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00

PhotoPrism — Event System

Last Updated: June 23, 2026

Overview

internal/event provides a lightweight pub/sub hub for in-process notifications. It underpins logging hooks, UI notifications, and domain events (entities created/updated/deleted/archived/restored). The package aliases the hub library to keep a stable interface while exposing simple helpers for common topics.

Usage

Publish a custom event:

event.Publish("photos.updated", event.Data{"ids": []string{"p1", "p2"}})

Publish localized notifications:

event.SuccessMsg(i18n.MsgIndexingCompletedIn, elapsed)
event.Warn("low disk space")

The *Msg helpers (SuccessMsg/ErrorMsg/InfoMsg/WarnMsg) publish a structured payload Data{"message", "messageId", "messageParams"}: message is the server-rendered string in the instance locale, messageId is the untranslated source string (i18n.Source(id)), and messageParams are the substitution values. The Web UI renders the notification from messageId + messageParams in each user's current UI language; message is a fallback. The plain Success/Error/Info/Warn string forms publish only message and are not localized — reserve them for already-translated or non-user-facing text.

Subscribe to topics:

sub := event.Subscribe("photos.*")
defer event.Unsubscribe(sub)
for msg := range sub.Receiver {
    fmt.Printf("topic=%s payload=%v\n", msg.Name, msg.Fields)
}

Log hook (used by default logger):

hook := event.NewHook(event.SharedHub())
log.AddHook(hook)

Entity events (content-channel payloads carry only identity strings — UIDs/slugs — never entity bodies):

event.EntitiesUpdated("photos", []string{photo.PhotoUID})
event.EntitiesDeleted("labels", []string{label.LabelUID})

Package Layout (Code Map)

  • Hub aliases & helpers: hub.go, format.go, time.go
  • Logging hook: log.go
  • Publish helpers: publish.go, publish_entities.go
  • Tests: package-level tests alongside sources
  • internal/photoprism — core indexing/import flows that emit events.
  • internal/server — HTTP layer that may consume event notifications.
  • internal/ai/vision & internal/ffmpeg — emit log events via the shared logger.
  • External hub library: github.com/leandro-lugaresi/hub

Testing

  • Lint: golangci-lint run ./internal/event...
  • Unit tests: go test ./internal/event/... (lightweight)

Notes

  • Use SharedHub() for process-wide subscriptions; NewHub() when isolating tests.
  • Topic separator is .; message separator for rendering is .
  • Keep notifications human-readable; payloads should be small to avoid blocking subscribers.