2020-10-24 05:16:35 +05:30
|
|
|
// 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 21:00:52 +05:30
|
|
|
"net/http"
|
2021-11-13 16:58:50 +05:30
|
|
|
"strconv"
|
2021-04-05 21:00:52 +05:30
|
|
|
|
2020-10-24 05:16:35 +05:30
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2021-07-24 21:33:58 +05:30
|
|
|
"code.gitea.io/gitea/modules/json"
|
2020-10-24 05:16:35 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// 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-11-13 16:58:50 +05:30
|
|
|
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 21:00:52 +05:30
|
|
|
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
2020-10-24 05:16:35 +05:30
|
|
|
"err": err,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-17 03:32:24 +05:30
|
|
|
message := task.Message
|
|
|
|
|
|
|
|
if task.Message != "" && task.Message[0] == '{' {
|
|
|
|
// assume message is actually a translatable string
|
|
|
|
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 21:00:52 +05:30
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
2020-10-24 05:16:35 +05:30
|
|
|
"status": task.Status,
|
2021-06-17 03:32:24 +05:30
|
|
|
"message": message,
|
2020-10-24 05:16:35 +05:30
|
|
|
"repo-id": task.RepoID,
|
|
|
|
"repo-name": opts.RepoName,
|
|
|
|
"start": task.StartTime,
|
|
|
|
"end": task.EndTime,
|
|
|
|
})
|
|
|
|
}
|