| @@ -6,6 +6,7 @@ package models | |||||
| import ( | import ( | ||||
| "bytes" | "bytes" | ||||
| "code.gitea.io/gitea/modules/log" | |||||
| "fmt" | "fmt" | ||||
| "io" | "io" | ||||
| "path" | "path" | ||||
| @@ -355,3 +356,18 @@ func getAllPublicAttachments(e Engine) ([]*Attachment, error) { | |||||
| attachments := make([]*Attachment, 0, 10) | attachments := make([]*Attachment, 0, 10) | ||||
| return attachments, e.Where("is_private = false and decompress_state = ?", DecompressStateDone).Find(&attachments) | return attachments, e.Where("is_private = false and decompress_state = ?", DecompressStateDone).Find(&attachments) | ||||
| } | } | ||||
| func GetPrivateAttachments(username string) ([]*Attachment, error) { | |||||
| user, err := getUserByName(x, username) | |||||
| if err != nil { | |||||
| log.Error("getUserByName(%s) failed:%v", username, err) | |||||
| return nil, err | |||||
| } | |||||
| return getPrivateAttachments(x, user.ID) | |||||
| } | |||||
| func getPrivateAttachments(e Engine, userID int64) ([]*Attachment, error) { | |||||
| attachments := make([]*Attachment, 0, 10) | |||||
| return attachments, e.Where("uploader_id = ? and decompress_state = ?", userID, DecompressStateDone).Find(&attachments) | |||||
| } | |||||
| @@ -617,6 +617,7 @@ email_notifications.disable=停用邮件通知 | |||||
| email_notifications.submit=邮件通知设置 | email_notifications.submit=邮件通知设置 | ||||
| [dataset] | [dataset] | ||||
| alert=如果要发起云脑任务,请上传zip格式的数据集 | |||||
| dataset=数据集 | dataset=数据集 | ||||
| dataset_setting=数据集设置 | dataset_setting=数据集设置 | ||||
| title=名称 | title=名称 | ||||
| @@ -29,7 +29,7 @@ const ( | |||||
| DecompressFailed = "1" | DecompressFailed = "1" | ||||
| ) | ) | ||||
| type PublicDataset struct { | |||||
| type CloudBrainDataset struct { | |||||
| UUID string `json:"id"` | UUID string `json:"id"` | ||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| Path string `json:"place"` | Path string `json:"place"` | ||||
| @@ -635,25 +635,44 @@ func QueryAllPublicDataset(ctx *context.Context){ | |||||
| return | return | ||||
| } | } | ||||
| var publicDatasets []PublicDataset | |||||
| queryDatasets(ctx, "admin", attachs) | |||||
| } | |||||
| func QueryPrivateDataset(ctx *context.Context){ | |||||
| username := ctx.Params(":username") | |||||
| attachs, err := models.GetPrivateAttachments(username) | |||||
| if err != nil { | |||||
| ctx.JSON(200, map[string]string{ | |||||
| "result_code": "-1", | |||||
| "error_msg": err.Error(), | |||||
| "data": "", | |||||
| }) | |||||
| return | |||||
| } | |||||
| queryDatasets(ctx, username, attachs) | |||||
| } | |||||
| func queryDatasets(ctx *context.Context, username string, attachs []*models.Attachment) { | |||||
| var datasets []CloudBrainDataset | |||||
| for _, attch := range attachs { | for _, attch := range attachs { | ||||
| has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(attch.UUID)) | has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(attch.UUID)) | ||||
| if err != nil || !has { | if err != nil || !has { | ||||
| continue | continue | ||||
| } | } | ||||
| publicDatasets = append(publicDatasets, PublicDataset{attch.UUID, | |||||
| datasets = append(datasets, CloudBrainDataset{attch.UUID, | |||||
| attch.Name, | attch.Name, | ||||
| setting.Attachment.Minio.RealPath + | setting.Attachment.Minio.RealPath + | ||||
| setting.Attachment.Minio.Bucket + "/" + | |||||
| setting.Attachment.Minio.BasePath + | |||||
| models.AttachmentRelativePath(attch.UUID) + | |||||
| attch.UUID, | |||||
| "admin", | |||||
| attch.CreatedUnix.Format("2006-01-02 03:04:05")}) | |||||
| setting.Attachment.Minio.Bucket + "/" + | |||||
| setting.Attachment.Minio.BasePath + | |||||
| models.AttachmentRelativePath(attch.UUID) + | |||||
| attch.UUID, | |||||
| username, | |||||
| attch.CreatedUnix.Format("2006-01-02 03:04:05")}) | |||||
| } | } | ||||
| data,err := json.Marshal(publicDatasets) | |||||
| data,err := json.Marshal(datasets) | |||||
| if err != nil { | if err != nil { | ||||
| log.Error("json.Marshal failed:", err.Error()) | log.Error("json.Marshal failed:", err.Error()) | ||||
| ctx.JSON(200, map[string]string{ | ctx.JSON(200, map[string]string{ | ||||
| @@ -669,4 +688,5 @@ func QueryAllPublicDataset(ctx *context.Context){ | |||||
| "error_msg": "", | "error_msg": "", | ||||
| "data": string(data), | "data": string(data), | ||||
| }) | }) | ||||
| return | |||||
| } | } | ||||
| @@ -535,8 +535,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Post("/decompress_done_notify", repo.UpdateAttachmentDecompressState) | m.Post("/decompress_done_notify", repo.UpdateAttachmentDecompressState) | ||||
| }) | }) | ||||
| m.Group("/attachments/public", func() { | |||||
| m.Get("/query", repo.QueryAllPublicDataset) | |||||
| m.Group("/attachments", func() { | |||||
| m.Get("/public/query", repo.QueryAllPublicDataset) | |||||
| m.Get("/private/:username", repo.QueryPrivateDataset) | |||||
| }, reqBasicAuth) | }, reqBasicAuth) | ||||
| m.Group("/:username", func() { | m.Group("/:username", func() { | ||||
| @@ -3,6 +3,11 @@ | |||||
| {{template "repo/header" .}} | {{template "repo/header" .}} | ||||
| <form class="ui container" action="{{.Link}}" method="post"> | <form class="ui container" action="{{.Link}}" method="post"> | ||||
| <input name="id" value="{{.dataset.ID}}" type="hidden" /> | <input name="id" value="{{.dataset.ID}}" type="hidden" /> | ||||
| <!-- | |||||
| <span class="alert" style="font-size:20px;color:red"> | |||||
| <strong>{{.i18n.Tr "dataset.alert"}}</strong> | |||||
| </span> | |||||
| --> | |||||
| <div id="datasetId" datasetId="{{.dataset.ID}}"> | <div id="datasetId" datasetId="{{.dataset.ID}}"> | ||||
| {{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
| {{template "base/alert" .}} | {{template "base/alert" .}} | ||||