From 71800440beb34e63e53756854b7726a19c815690 Mon Sep 17 00:00:00 2001 From: Mohammad Mahdi Date: Tue, 29 Jul 2025 17:55:16 +0330 Subject: [PATCH] Add imagekit fallback on no imagekit ID --- internal/config/config.go | 4 ++-- internal/services/imgKitHelper.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 789e125..6471115 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -31,7 +31,7 @@ var Config *config func Load() *config { err := godotenv.Load() if err != nil { - slog.Error("Error loading .env file - Using environment variables instead") + slog.Warn("Error loading .env file - Using environment variables instead") } // Get mastodon instance @@ -86,7 +86,7 @@ func Load() *config { imageKitId := os.Getenv("CAOM_IMAGEKIT_ID") if imageKitId == "" { - slog.Info("No imagekit id provided, not using imagekit") + slog.Info("No imagekit id provided, not using imagekit.io") } // Inititlize AppContext var appContext = &config{ diff --git a/internal/services/imgKitHelper.go b/internal/services/imgKitHelper.go index 3c5801b..92f3115 100644 --- a/internal/services/imgKitHelper.go +++ b/internal/services/imgKitHelper.go @@ -12,9 +12,15 @@ func InitImgKitHelper() { } func GetPreviewUrl(url string) string { + if config.Config.ImageKitId == "" { + return url + } return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:w-500,h-500,c-at_max,f-webp,q-60/" + url } func GetRemoteUrl(url string) string { + if config.Config.ImageKitId == "" { + return url + } return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url }