Browse Source

add dir

tags/vopendata0.1.2
yuyuanshifu 5 years ago
parent
commit
e9ffe6a70c
7 changed files with 78 additions and 9 deletions
  1. +0
    -3
      go.sum
  2. +3
    -0
      modules/setting/setting.go
  3. +1
    -0
      options/locale/locale_zh-CN.ini
  4. +56
    -6
      routers/repo/attachment.go
  5. +1
    -0
      routers/routes/routes.go
  6. +4
    -0
      templates/repo/datasets/dataset_list.tmpl
  7. +13
    -0
      web_src/js/index.js

+ 0
- 3
go.sum View File

@@ -290,7 +290,6 @@ github.com/go-openapi/validate v0.19.3 h1:PAH/2DylwWcIU1s0Y7k3yNmeAgWOcKrNE2Q7Ww
github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7vS9k0lo6zwJo=
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-resty/resty v1.12.0 h1:L1P5qymrXL5H/doXe2pKUr1wxovAI5ilm2LdVLbwThc=
github.com/go-resty/resty/v2 v2.3.0 h1:JOOeAvjSlapTT92p8xiS19Zxev1neGikoHsXJeOq8So=
github.com/go-resty/resty/v2 v2.3.0/go.mod h1:UpN9CgLZNsv4e9XG50UU8xdI0F43UQ4HmxLBDwaroHU=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
@@ -842,8 +841,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f h1:QBjCr1Fz5kw158VqdE9JfI9cJnl/ymnJWAdMuinqL7Y=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=


+ 3
- 0
modules/setting/setting.go View File

@@ -309,6 +309,7 @@ var (
Bucket string
Location string
BasePath string
RealPath string
}
AllowedTypes string
MaxSize int64
@@ -324,6 +325,7 @@ var (
Bucket string
Location string
BasePath string
RealPath string
}{},
AllowedTypes: "image/jpeg,image/png,application/zip,application/gzip",
MaxSize: 4,
@@ -892,6 +894,7 @@ func NewContext() {
Attachment.Minio.Location = sec.Key("MINIO_LOCATION").MustString("us-east-1")
Attachment.Minio.BasePath = sec.Key("MINIO_BASE_PATH").MustString("attachments/")
Attachment.Minio.UseSSL = sec.Key("MINIO_USE_SSL").MustBool(false)
Attachment.Minio.RealPath = sec.Key("MINIO_REAL_PATH").MustString("/mnt/test/minio/data/")
}

Attachment.AllowedTypes = strings.Replace(sec.Key("ALLOWED_TYPES").MustString("image/jpeg,image/png,application/zip,application/gzip"), "|", ",", -1)


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

@@ -644,6 +644,7 @@ download_count = 下载统计
edit=编辑
private=私有
public=公有
dir=目录
back=返回
copy_url=复制下载链接
visibility=可见性


+ 56
- 6
routers/repo/attachment.go View File

@@ -5,12 +5,6 @@
package repo

import (
contexExt "context"
"fmt"
"net/http"
"strconv"
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -18,6 +12,15 @@ import (
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/worker"
contexExt "context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"path"
"strconv"
"strings"
"time"

gouuid "github.com/satori/go.uuid"
)
@@ -28,6 +31,12 @@ const (
DecompressFailed = "1"
)

type FileInfo struct {
FileName string
ModTime time.Time
IsDir bool
}

func RenderAttachmentSettings(ctx *context.Context) {
renderAttachmentSettings(ctx)
}
@@ -351,3 +360,44 @@ func HandleUnDecompressAttachment() {

return
}

func GetDir(ctx *context.Context) {
uuid := ctx.Query("uuid")

//todo: 查询解压状态成功之后才能查看文件目录
files, err := ioutil.ReadDir(setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath +
path.Join(uuid[0:1], uuid[1:2], uuid + uuid) + "/" + ctx.Query("parentDir"))
if err != nil {
log.Error("ReadDir failed:", err.Error())
ctx.ServerError("ReadDir failed:", err)
return
}

i := 1
var fileInfos []FileInfo
for _, file := range files {
if i > 100 {
break
}

fileInfos = append(fileInfos, FileInfo{
FileName:file.Name(),
ModTime:file.ModTime(),
IsDir:file.IsDir(),
})
i++
}

tmp, err := json.Marshal(fileInfos)
if err != nil {
ctx.ServerError("json.Marshal failed:", err)
return
}

log.Info(string(tmp))

ctx.JSON(200, map[string]string{
"uuid": uuid,
"fileInfos": string(tmp),
})
}

+ 1
- 0
routers/routes/routes.go View File

@@ -521,6 +521,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/get_pre_url", repo.GetPresignedPutObjectURL)
m.Post("/add", repo.AddAttachment)
m.Post("/private", repo.UpdatePublicAttachment)
m.Get("/dir", repo.GetDir)
}, reqSignIn)

m.Group("/attachments", func() {


+ 4
- 0
templates/repo/datasets/dataset_list.tmpl View File

@@ -18,6 +18,10 @@
<span class="ui text center clipboard" data-clipboard-text="{{.DownloadURL}}" data-tooltip='{{$.i18n.Tr "dataset.copy_url"}}' data-clipboard-action="copy">{{svg "octicon-file" 16}}</span>
</div>

<div class="two wide column">
<a class="ui button mini" href="javascript:void(0)" data-uuid={{.UUID}} data-dataset-dir data-dir-url="{{AppSubUrl}}/attachments/dir" data-csrf="{{$.CsrfToken}}">{{$.i18n.Tr "dataset.dir"}}</a>
</div>

{{if $.Permission.CanWrite $.UnitTypeDatasets}}
<div class="three wide column">
<div class="ui buttons mini">


+ 13
- 0
web_src/js/index.js View File

@@ -1130,6 +1130,19 @@ async function initRepository() {
}
}).modal('show');
});
$('[data-dataset-dir]').on('click', function () {
const $this = $(this);
$.get($this.data('dir-url'), {
_csrf: $this.data('csrf'),
uuid: $this.data('uuid'),
//parentDir: $this.data('parentDir')
parentDir: "test"
}).done((_data) => {
$(`#${$this.data('uuid')}`).hide();
}).fail(() => {
//window.location.reload();
});
});
$('[data-category-id]').on('click', function () {
const category = $(this).data('category-id');
$('#category').val(category);


Loading…
Cancel
Save