@@ -290,24 +290,27 @@ func GetAllObsListObjectUnderDir(bucket string, prefix string) ([]FileInfo, erro | |||||
if err == nil { | if err == nil { | ||||
for _, val := range output.Contents { | for _, val := range output.Contents { | ||||
var isDir bool | var isDir bool | ||||
var fileName, parentDir string | |||||
if val.Key == prefix { | if val.Key == prefix { | ||||
continue | continue | ||||
} | } | ||||
log.Info("sub str=" + val.Key[prefixLen:len(val.Key)-1]) | |||||
if strings.Contains(val.Key[prefixLen:len(val.Key)-1], "/") { | if strings.Contains(val.Key[prefixLen:len(val.Key)-1], "/") { | ||||
continue | continue | ||||
} | } | ||||
if strings.HasSuffix(val.Key, "/") { | if strings.HasSuffix(val.Key, "/") { | ||||
isDir = true | isDir = true | ||||
fileName = val.Key[prefixLen : len(val.Key)-1] | |||||
parentDir = val.Key[prefixLen:] | |||||
} else { | } else { | ||||
isDir = false | isDir = false | ||||
fileName = val.Key[prefixLen:] | |||||
} | } | ||||
fileInfo := FileInfo{ | fileInfo := FileInfo{ | ||||
ModTime: val.LastModified.Format("2006-01-02 15:04:05"), | ModTime: val.LastModified.Format("2006-01-02 15:04:05"), | ||||
FileName: val.Key[prefixLen:], | |||||
FileName: fileName, | |||||
Size: val.Size, | Size: val.Size, | ||||
IsDir: isDir, | IsDir: isDir, | ||||
ParenDir: "", | |||||
ParenDir: parentDir, | |||||
} | } | ||||
fileInfos = append(fileInfos, fileInfo) | fileInfos = append(fileInfos, fileInfo) | ||||
} | } | ||||
@@ -202,8 +202,11 @@ func DownloadMultiModelFile(ctx *context.Context) { | |||||
func DownloadSingleModelFile(ctx *context.Context) { | func DownloadSingleModelFile(ctx *context.Context) { | ||||
log.Info("DownloadSingleModelFile start.") | log.Info("DownloadSingleModelFile start.") | ||||
path := ctx.Query("path") | |||||
url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, path[len(setting.Bucket)+1:]) | |||||
id := ctx.Params(":ID") | |||||
parentDir := ctx.Query("parentDir") | |||||
fileName := ctx.Query("fileName") | |||||
path := Model_prefix + models.AttachmentRelativePath(id) + "/" + parentDir + fileName | |||||
url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, path) | |||||
if err != nil { | if err != nil { | ||||
log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) | log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) | ||||
ctx.ServerError("GetObsCreateSignedUrl", err) | ctx.ServerError("GetObsCreateSignedUrl", err) | ||||
@@ -214,7 +217,7 @@ func DownloadSingleModelFile(ctx *context.Context) { | |||||
func ShowSingleModel(ctx *context.Context) { | func ShowSingleModel(ctx *context.Context) { | ||||
id := ctx.Params(":ID") | id := ctx.Params(":ID") | ||||
//parentDir := ctx.Query("parentDir") | |||||
parentDir := ctx.Query("parentDir") | |||||
log.Info("Show single ModelInfo start.id=" + id) | log.Info("Show single ModelInfo start.id=" + id) | ||||
task, err := models.QueryModelById(id) | task, err := models.QueryModelById(id) | ||||
if err != nil { | if err != nil { | ||||
@@ -222,8 +225,8 @@ func ShowSingleModel(ctx *context.Context) { | |||||
ctx.ServerError("no such model:", err) | ctx.ServerError("no such model:", err) | ||||
return | return | ||||
} | } | ||||
log.Info("bucket=" + setting.Bucket + " key=" + task.Path[len(setting.Bucket)+1:]) | |||||
models, err := storage.GetAllObsListObjectUnderDir(setting.Bucket, task.Path[len(setting.Bucket)+1:]) | |||||
log.Info("bucket=" + setting.Bucket + " key=" + task.Path[len(setting.Bucket)+1:] + parentDir) | |||||
models, err := storage.GetAllObsListObjectUnderDir(setting.Bucket, task.Path[len(setting.Bucket)+1:]+parentDir) | |||||
if err != nil { | if err != nil { | ||||
log.Info("get model list failed:", err) | log.Info("get model list failed:", err) | ||||
ctx.ServerError("GetObsListObject:", err) | ctx.ServerError("GetObsListObject:", err) | ||||
@@ -964,6 +964,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
m.Get("", reqRepoCloudBrainReader, repo.ShowModelPageInfo) | m.Get("", reqRepoCloudBrainReader, repo.ShowModelPageInfo) | ||||
m.Group("/:ID", func() { | m.Group("/:ID", func() { | ||||
m.Get("", reqRepoCloudBrainReader, repo.ShowSingleModel) | m.Get("", reqRepoCloudBrainReader, repo.ShowSingleModel) | ||||
m.Get("/downloadsingle", reqRepoCloudBrainReader, repo.DownloadSingleModelFile) | |||||
}) | }) | ||||
}, context.RepoRef()) | }, context.RepoRef()) | ||||
@@ -27,7 +27,7 @@ | |||||
<td class="name four wide"> | <td class="name four wide"> | ||||
<span class="truncate"> | <span class="truncate"> | ||||
<span class="octicon octicon-file-directory"></span> | <span class="octicon octicon-file-directory"></span> | ||||
<a class="title" href="{{if .IsDir}}{{$.RepoLink}}/modelmanage/downloadsingle?id={{$.ID}}&parentDir={{.ParenDir}}{{else}}{{$.RepoLink}}/modelmanage/downloadsingle?id={{$.ID}}&parentDir={{.ParenDir}}&fileName={{.FileName}}{{end}}"> | |||||
<a class="title" href="{{if .IsDir}}{{$.RepoLink}}/modelmanage/{{$.ID}}?parentDir={{.ParenDir}}{{else}}{{$.RepoLink}}/modelmanage/{{$.ID}}/downloadsingle?parentDir={{.ParenDir}}&fileName={{.FileName}}{{end}}"> | |||||
<span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}} | <span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}} | ||||
</a> | </a> | ||||
</span> | </span> | ||||