From 57c2cb3737301757f97720de23dbd8d08da59e90 Mon Sep 17 00:00:00 2001 From: Jianyun Date: Thu, 22 Aug 2024 10:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/calibre/api.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/calibre/api.go b/internal/calibre/api.go index 10d3b76..9da5d77 100644 --- a/internal/calibre/api.go +++ b/internal/calibre/api.go @@ -345,7 +345,24 @@ func (c Api) getFileOrCache(id string) (string, error) { } func (c Api) switchIndex(c2 *gin.Context) { - _, err := c.client.SwapIndexes( + + resp, err := c.client.GetTasks(&meilisearch.TasksQuery{ + Limit: 2, + Statuses: []string{"enqueued", "processing"}, + IndexUIDS: []string{c.config.Search.Index, c.config.Search.Index + "-bak"}, + }) + if err != nil { + log.Warn(err) + c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()}) + return + } + if len(resp.Results) != 0 { + log.Warn(err) + c2.JSON(http.StatusInternalServerError, gin.H{"code": 400, "error": "有任务正在执行,请稍后再试"}) + return + } + + _, err = c.client.SwapIndexes( []meilisearch.SwapIndexesParams{ { Indexes: []string{c.config.Search.Index, c.config.Search.Index + "-bak"},