From 46904fa4da33fd4ff54bce1efed4ab1ee79db9bf Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 8 Dec 2022 15:16:53 +0800 Subject: [PATCH] fix-3221 --- routers/api/v1/repo/cloudbrain.go | 39 ++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index cd8340c41..d724149df 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -9,6 +9,7 @@ import ( "bufio" "encoding/json" "io" + "io/ioutil" "net/http" "os" "path" @@ -621,6 +622,19 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { } } + existStr := "testduibudui+" + "" + if job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference) { + if job.Type == models.TypeCloudBrainOne { + result, err := cloudbrain.GetJob(job.JobID) + if err == nil && result != nil { + jobRes, _ := models.ConvertToJobResultPayload(result.Payload) + taskRoles := jobRes.TaskRoles + taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) + existStr = taskRes.TaskStatuses[0].ExitDiagnostics + } + } + } + logDir := "/model" if job.JobType == string(models.JobTypeInference) || job.JobType == string(models.JobTypeModelSafety) { logDir = cloudbrain.ResultPath @@ -638,17 +652,30 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { } } if fileName != "" { - prefix := "/" + setting.CBCodePathPrefix + job.JobName + logDir - url, err := storage.Attachments.PresignedGetURL(prefix+"/"+fileName, fileName) + prefix := "/" + setting.CBCodePathPrefix + job.JobName + "/model" + filePath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + prefix + "/" + fileName + // Read the file contents into a byte slice + data, err := ioutil.ReadFile(filePath) if err != nil { - log.Error("Get minio get SignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("ReadFile", err) + return + } + + // Set the appropriate response headers + ctx.Resp.Header().Set("Content-Type", "application/octet-stream") + ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName) + + // Write the file contents to the response + if _, err := ctx.Resp.Write(data); err != nil { + ctx.ServerError("Write", err) + return + } + if _, err := ctx.Resp.Write([]byte(existStr)); err != nil { + log.Error("Write failed: %v", err.Error(), ctx.Data["msgID"]) return } - log.Info("fileName=" + fileName) - http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusTemporaryRedirect) } else { log.Info("fileName is null.") - } }