2020-10-24 05:16:35 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-10-24 05:16:35 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
2022-08-25 08:01:57 +05:30
|
|
|
admin_model "code.gitea.io/gitea/models/admin"
|
2020-10-24 05:16:35 +05:30
|
|
|
"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) {
|
2023-09-16 20:09:12 +05:30
|
|
|
task, opts, err := admin_model.GetMigratingTaskByID(ctx, ctx.ParamsInt64("task"), ctx.Doer.ID)
|
2020-10-24 05:16:35 +05:30
|
|
|
if err != nil {
|
2022-08-25 08:01:57 +05:30
|
|
|
if admin_model.IsErrTaskDoesNotExist(err) {
|
2023-07-05 00:06:08 +05:30
|
|
|
ctx.JSON(http.StatusNotFound, map[string]any{
|
2021-11-13 16:58:50 +05:30
|
|
|
"error": "task `" + strconv.FormatInt(ctx.ParamsInt64("task"), 10) + "` does not exist",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2023-07-05 00:06:08 +05:30
|
|
|
ctx.JSON(http.StatusInternalServerError, map[string]any{
|
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
|
2022-08-25 08:01:57 +05:30
|
|
|
var translatableMessage admin_model.TranslatableMessage
|
2021-06-17 03:32:24 +05:30
|
|
|
if err := json.Unmarshal([]byte(message), &translatableMessage); err != nil {
|
2022-08-25 08:01:57 +05:30
|
|
|
translatableMessage = admin_model.TranslatableMessage{
|
2021-06-17 03:32:24 +05:30
|
|
|
Format: "migrate.migrating_failed.error",
|
2023-07-05 00:06:08 +05:30
|
|
|
Args: []any{task.Message},
|
2021-06-17 03:32:24 +05:30
|
|
|
}
|
|
|
|
}
|
2024-02-15 03:18:45 +05:30
|
|
|
message = ctx.Locale.TrString(translatableMessage.Format, translatableMessage.Args...)
|
2021-06-17 03:32:24 +05:30
|
|
|
}
|
|
|
|
|
2023-07-05 00:06:08 +05:30
|
|
|
ctx.JSON(http.StatusOK, map[string]any{
|
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,
|
|
|
|
})
|
|
|
|
}
|