Browse Source

add private

master
yuyuanshifu 4 years ago
parent
commit
246f0a3e49
8 changed files with 55 additions and 12 deletions
  1. BIN
      docs/opendata对外接口文档.docx
  2. BIN
      docs/开源社区与云脑平台对接方案(2)(1).docx
  3. BIN
      docs/开源社区与云脑平台对接方案.docx
  4. +16
    -0
      models/attachment.go
  5. +1
    -0
      options/locale/locale_zh-CN.ini
  6. +30
    -10
      routers/repo/attachment.go
  7. +3
    -2
      routers/routes/routes.go
  8. +5
    -0
      templates/repo/datasets/index.tmpl

BIN
docs/opendata对外接口文档.docx View File


BIN
docs/开源社区与云脑平台对接方案(2)(1).docx View File


BIN
docs/开源社区与云脑平台对接方案.docx View File


+ 16
- 0
models/attachment.go View File

@@ -6,6 +6,7 @@ package models

import (
"bytes"
"code.gitea.io/gitea/modules/log"
"fmt"
"io"
"path"
@@ -355,3 +356,18 @@ func getAllPublicAttachments(e Engine) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
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)
}


+ 1
- 0
options/locale/locale_zh-CN.ini View File

@@ -617,6 +617,7 @@ email_notifications.disable=停用邮件通知
email_notifications.submit=邮件通知设置

[dataset]
alert=如果要发起云脑任务,请上传zip格式的数据集
dataset=数据集
dataset_setting=数据集设置
title=名称


+ 30
- 10
routers/repo/attachment.go View File

@@ -29,7 +29,7 @@ const (
DecompressFailed = "1"
)

type PublicDataset struct {
type CloudBrainDataset struct {
UUID string `json:"id"`
Name string `json:"name"`
Path string `json:"place"`
@@ -635,25 +635,44 @@ func QueryAllPublicDataset(ctx *context.Context){
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 {
has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(attch.UUID))
if err != nil || !has {
continue
}

publicDatasets = append(publicDatasets, PublicDataset{attch.UUID,
datasets = append(datasets, CloudBrainDataset{attch.UUID,
attch.Name,
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 {
log.Error("json.Marshal failed:", err.Error())
ctx.JSON(200, map[string]string{
@@ -669,4 +688,5 @@ func QueryAllPublicDataset(ctx *context.Context){
"error_msg": "",
"data": string(data),
})
return
}

+ 3
- 2
routers/routes/routes.go View File

@@ -535,8 +535,9 @@ func RegisterRoutes(m *macaron.Macaron) {
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)

m.Group("/:username", func() {


+ 5
- 0
templates/repo/datasets/index.tmpl View File

@@ -3,6 +3,11 @@
{{template "repo/header" .}}
<form class="ui container" action="{{.Link}}" method="post">
<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}}">
{{.CsrfTokenHtml}}
{{template "base/alert" .}}


Loading…
Cancel
Save