From 0c68133138dd78a7c34e15e343a9bf86879a18b0 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 7 Jul 2022 11:10:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/ai_model_convert.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/routers/repo/ai_model_convert.go b/routers/repo/ai_model_convert.go index aadddde5f..538cf2f69 100644 --- a/routers/repo/ai_model_convert.go +++ b/routers/repo/ai_model_convert.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "net/http" "os" + "path" "strings" "code.gitea.io/gitea/models" @@ -661,13 +662,21 @@ func ModelConvertDownloadModel(ctx *context.Context) { ctx.ServerError("no file to download.", err) } } else { - + Prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, job.CloudBrainTaskId, "output/", "V0001", ""), "/") + allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, Prefix) + if err == nil { + returnFileName := job.Name + ".zip" + ObsDownloadManyFile(Prefix, ctx, returnFileName, allFile) + } else { + log.Info("error,msg=" + err.Error()) + ctx.ServerError("no file to download.", err) + } } } else { + parentDir := ctx.Query("parentDir") + fileName := ctx.Query("fileName") + jobName := ctx.Query("jobName") if job.IsGpuTrainTask() { - parentDir := ctx.Query("parentDir") - fileName := ctx.Query("fileName") - jobName := ctx.Query("jobName") filePath := "jobs/" + jobName + "/model/" + parentDir url, err := storage.Attachments.PresignedGetURL(filePath, fileName) if err != nil { @@ -679,6 +688,15 @@ func ModelConvertDownloadModel(ctx *context.Context) { http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusTemporaryRedirect) } else { //TODO + ObjectKey := path.Join(setting.TrainJobModelPath, job.CloudBrainTaskId, "output/", "V0001", parentDir, fileName) + log.Info("ObjectKey=" + ObjectKey) + url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, ObjectKey) + if err != nil { + log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("GetObsCreateSignedUrl", err) + return + } + http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) } }