2020-10-23 23:46:35 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
2021-04-05 15:30:52 +00:00
|
|
|
"net/http"
|
2021-12-25 15:45:51 +00:00
|
|
|
"strconv"
|
2021-04-05 15:30:52 +00:00
|
|
|
|
2020-10-23 23:46:35 +00:00
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2021-06-16 22:02:24 +00:00
|
|
|
jsoniter "github.com/json-iterator/go"
|
2020-10-23 23:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TaskStatus returns task's status
|
|
|
|
func TaskStatus(ctx *context.Context) {
|
|
|
|
task, opts, err := models.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.User.ID)
|
|
|
|
if err != nil {
|
2021-12-25 15:45:51 +00:00
|
|
|
if models.IsErrTaskDoesNotExist(err) {
|
|
|
|
ctx.JSON(http.StatusNotFound, map[string]interface{}{
|
|
|
|
"error": "task `" + strconv.FormatInt(ctx.ParamsInt64("task"), 10) + "` does not exist",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
2020-10-23 23:46:35 +00:00
|
|
|
"err": err,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-16 22:02:24 +00:00
|
|
|
message := task.Message
|
|
|
|
|
|
|
|
if task.Message != "" && task.Message[0] == '{' {
|
|
|
|
// assume message is actually a translatable string
|
|
|
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
|
|
|
var translatableMessage models.TranslatableMessage
|
|
|
|
if err := json.Unmarshal([]byte(message), &translatableMessage); err != nil {
|
|
|
|
translatableMessage = models.TranslatableMessage{
|
|
|
|
Format: "migrate.migrating_failed.error",
|
|
|
|
Args: []interface{}{task.Message},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message = ctx.Tr(translatableMessage.Format, translatableMessage.Args...)
|
|
|
|
}
|
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
2020-10-23 23:46:35 +00:00
|
|
|
"status": task.Status,
|
2021-06-16 22:02:24 +00:00
|
|
|
"message": message,
|
2020-10-23 23:46:35 +00:00
|
|
|
"repo-id": task.RepoID,
|
|
|
|
"repo-name": opts.RepoName,
|
|
|
|
"start": task.StartTime,
|
|
|
|
"end": task.EndTime,
|
|
|
|
})
|
|
|
|
}
|