From e9ffe6a70c566293c026ae0a37b2946985bca677 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Wed, 5 Aug 2020 18:06:37 +0800 Subject: [PATCH] add dir --- go.sum | 3 -- modules/setting/setting.go | 3 ++ options/locale/locale_zh-CN.ini | 1 + routers/repo/attachment.go | 62 ++++++++++++++++++++--- routers/routes/routes.go | 1 + templates/repo/datasets/dataset_list.tmpl | 4 ++ web_src/js/index.js | 13 +++++ 7 files changed, 78 insertions(+), 9 deletions(-) mode change 100644 => 100755 go.sum mode change 100644 => 100755 templates/repo/datasets/dataset_list.tmpl mode change 100644 => 100755 web_src/js/index.js diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 index 91fa2473d..76ebbf068 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cd24597b9..8da1d916a 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -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) diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index e683b92a6..6fa3769d6 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -644,6 +644,7 @@ download_count = 下载统计 edit=编辑 private=私有 public=公有 +dir=目录 back=返回 copy_url=复制下载链接 visibility=可见性 diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index f40783bc2..3a5f514c7 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -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), + }) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index b144e855f..ce941dfcb 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -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() { diff --git a/templates/repo/datasets/dataset_list.tmpl b/templates/repo/datasets/dataset_list.tmpl old mode 100644 new mode 100755 index 2eb79f0ea..c6b43036c --- a/templates/repo/datasets/dataset_list.tmpl +++ b/templates/repo/datasets/dataset_list.tmpl @@ -18,6 +18,10 @@ {{svg "octicon-file" 16}} +
+ {{$.i18n.Tr "dataset.dir"}} +
+ {{if $.Permission.CanWrite $.UnitTypeDatasets}}
diff --git a/web_src/js/index.js b/web_src/js/index.js old mode 100644 new mode 100755 index 1c2ab7b2c..0776a7a9e --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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);