From 75eae43f6035cd865cad0e05aec43dc07b0c6742 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 5 May 2023 12:03:35 +0200 Subject: [PATCH] admin: auto-sync tries to sync themes if it doesn't exists yet --- admin/api/sync.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/admin/api/sync.go b/admin/api/sync.go index a9ce8592..f9be0378 100644 --- a/admin/api/sync.go +++ b/admin/api/sync.go @@ -234,8 +234,30 @@ func autoSync(c *gin.Context) { } if theTheme == nil { - c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Theme not found %q", p)}) - return + // The theme doesn't exists locally, perhaps it has not been imported already? + rThemes, err := sync.GetThemes(sync.GlobalImporter) + if err == nil { + for _, theme := range rThemes { + if theme == p { + sync.SyncThemes(sync.GlobalImporter) + + themes, err := fic.GetThemes() + if err == nil { + for _, theme := range themes { + if theme.Path == p { + theTheme = theme + break + } + } + } + } + } + } + + if theTheme == nil { + c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Theme not found %q", p)}) + return + } } if !IsProductionEnv {