Add imagekit fallback on no imagekit ID

This commit is contained in:
2025-07-29 17:55:16 +03:30
parent 051408fcdd
commit 71800440be
2 changed files with 8 additions and 2 deletions

View File

@@ -31,7 +31,7 @@ var Config *config
func Load() *config { func Load() *config {
err := godotenv.Load() err := godotenv.Load()
if err != nil { 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 // Get mastodon instance
@@ -86,7 +86,7 @@ func Load() *config {
imageKitId := os.Getenv("CAOM_IMAGEKIT_ID") imageKitId := os.Getenv("CAOM_IMAGEKIT_ID")
if imageKitId == "" { if imageKitId == "" {
slog.Info("No imagekit id provided, not using imagekit") slog.Info("No imagekit id provided, not using imagekit.io")
} }
// Inititlize AppContext // Inititlize AppContext
var appContext = &config{ var appContext = &config{

View File

@@ -12,9 +12,15 @@ func InitImgKitHelper() {
} }
func GetPreviewUrl(url string) string { 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 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 { 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 return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url
} }