From 4a21c835d322fb2d4e68b9ab29a04c97cdb98746 Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Thu, 9 Feb 2023 12:02:22 +0800 Subject: [PATCH] Add notification config in seafile.conf (#593) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 杨赫然 --- notification-server/server.go | 8 +++---- server/seafile-session.c | 42 ++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/notification-server/server.go b/notification-server/server.go index 560491d..89f9b89 100644 --- a/notification-server/server.go +++ b/notification-server/server.go @@ -35,14 +35,14 @@ func init() { } func loadNotifConfig() { - notifyConfPath := filepath.Join(configDir, "notification.conf") + notifyConfPath := filepath.Join(configDir, "seafile.conf") config, err := ini.Load(notifyConfPath) if err != nil { log.Fatalf("Failed to load notification.conf: %v", err) } - section, err := config.GetSection("general") + section, err := config.GetSection("notification") if err != nil { log.Fatal("No general section in seafile.conf.") } @@ -65,11 +65,11 @@ func loadNotifConfig() { logLevel = key.String() } - if key, err := section.GetKey("private_key"); err == nil { + if key, err := section.GetKey("jwt_private_key"); err == nil { privateKey = key.String() } - if key, err := section.GetKey("notification_token"); err == nil { + if key, err := section.GetKey("seafile_auth_token"); err == nil { notifToken = key.String() } diff --git a/server/seafile-session.c b/server/seafile-session.c index 85e613d..55d2460 100644 --- a/server/seafile-session.c +++ b/server/seafile-session.c @@ -44,7 +44,9 @@ seafile_session_new(const char *central_config_dir, GKeyFile *config; GKeyFile *ccnet_config; SeafileSession *session = NULL; - char *notif_url = NULL; + gboolean notif_enabled = FALSE; + char *notif_server = NULL; + int notif_port = 8083; char *notif_token = NULL; char *private_key = NULL; @@ -126,18 +128,24 @@ seafile_session_new(const char *central_config_dir, g_free (type); } - notif_url = g_key_file_get_string (config, - "notification", "notification_url", - NULL); + notif_enabled = g_key_file_get_boolean (config, + "notification", "enabled", + NULL); + if (notif_enabled) { + notif_server = g_key_file_get_string (config, + "notification", "host", + NULL); + notif_port = g_key_file_get_integer (config, + "notification", "port", + NULL); - notif_token = g_key_file_get_string (config, - "notification", "notification_token", - NULL); + notif_token = g_key_file_get_string (config, + "notification", "seafile_auth_token", + NULL); - private_key = g_key_file_get_string (config, - "notification", "private_key", - NULL); - if (private_key) { + private_key = g_key_file_get_string (config, + "notification", "jwt_private_key", + NULL); session->private_key = private_key; } @@ -222,16 +230,20 @@ seafile_session_new(const char *central_config_dir, if (!session->org_mgr) goto onerror; - if (notif_url != NULL && notif_token != NULL) { - session->notif_mgr = seaf_notif_manager_new (session, notif_url, notif_token); - if (!session->notif_mgr) + if (notif_enabled && notif_server != NULL && notif_token != NULL) { + char notif_url[128]; + g_sprintf (notif_url, "%s:%d", notif_server, notif_port); + session->notif_mgr = seaf_notif_manager_new (session, g_strdup (notif_url), notif_token); + if (!session->notif_mgr) { + g_free (notif_url); goto onerror; + } } return session; onerror: - g_free (notif_url); + g_free (notif_server); g_free (notif_token); g_free (private_key); free (abs_seafile_dir);