Browse Source

add file dir

tags/v1.21.12.1
yuyuanshifu 5 years ago
parent
commit
42243b308b
4 changed files with 49 additions and 104 deletions
  1. +18
    -64
      routers/repo/dir.go
  2. +14
    -14
      templates/repo/datasets/dirs/dir_list.tmpl
  3. +17
    -15
      templates/repo/datasets/dirs/index.tmpl
  4. +0
    -11
      web_src/js/index.js

+ 18
- 64
routers/repo/dir.go View File

@@ -6,7 +6,6 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"encoding/json"
"errors"
"io/ioutil"
"path"
@@ -22,68 +21,18 @@ type FileInfo struct {
ModTime string
IsDir bool
Size int64
ParenDir string
UUID string
}

func DirIndex(ctx *context.Context) {
uuid := ctx.Params("uuid")

attachment, err := models.GetAttachmentByUUID(uuid)
if err != nil {
ctx.ServerError("GetDatasetAttachments", err)
return
}

if !strings.HasSuffix(attachment.Name, ".zip") {
log.Error("The file is not zip file, can not query the dir")
ctx.ServerError("The file is not zip file, can not query the dir", errors.New("The file is not zip file, can not query the dir"))
return
} else {
if attachment.DecompressState != models.DecompressStateDone {
log.Error("The file has not been decompressed completely now")
ctx.ServerError("The file has not been decompressed completely now", errors.New("The file has not been decompressed completely now"))
return
}
}

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) + "/" )
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().Format("2006-01-02 15:04:05"),
IsDir:file.IsDir(),
Size:file.Size(),
})
i++
}

ctx.Data["Dirs"] = fileInfos

ctx.Data["Title"] = attachment.Name

ctx.HTML(200, tplDirIndex)
}

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

if parentDir == "" {
attachment, err := models.GetAttachmentByUUID(uuid)
if err != nil {
ctx.ServerError("GetAttachmentByUUID failed:", err)
ctx.ServerError("GetDatasetAttachments", err)
return
}

@@ -115,24 +64,29 @@ func GetDir(ctx *context.Context) {
break
}

log.Info(file.Name())

var tmp string
if parentDir == "" {
tmp = file.Name()
} else {
tmp = parentDir + "/" + file.Name()
}

fileInfos = append(fileInfos, FileInfo{
FileName:file.Name(),
ModTime:file.ModTime().Format("2006-01-02 15:04:05"),
IsDir:file.IsDir(),
Size:file.Size(),
ParenDir:tmp,
UUID:uuid,
})
i++
}

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

ctx.Data["Dirs"] = fileInfos

ctx.JSON(200, map[string]string{
"uuid": uuid,
"fileInfos": string(tmp),
})
ctx.Data["Title"] = attachment.Name

ctx.HTML(200, tplDirIndex)
}

+ 14
- 14
templates/repo/datasets/dirs/dir_list.tmpl View File

@@ -1,20 +1,20 @@
{{if .Dirs}}
{{range .Dirs}}
<div class="ui grid item">
<div class="row">
<div class="six wide column">
<a class="title" href="{{if .IsDir}}{{AppSubUrl}}/attachments/dir{{end}}">
<span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}}
</a>
</div>
<div class="two wide column">
{{.Size | FileSize}}
</div>
<div class="six wide column">
<span>{{.ModTime}}</span>
</div>
<div class="ui grid item">
<div class="row">
<div class="six wide column">
<a class="title" href="{{if .IsDir}}{{$.RepoLink}}/datasets/dirs/{{.UUID}}?parentDir={{.ParenDir}}{{end}}">
<span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}}
</a>
</div>
<div class="two wide column">
{{.Size | FileSize}}
</div>
<div class="six wide column">
<span>{{.ModTime}}</span>
</div>

</div>
</div>
</div>
{{end}}
{{end}}

+ 17
- 15
templates/repo/datasets/dirs/index.tmpl View File

@@ -9,25 +9,27 @@
</div>
</div>
</div>
</form>
</div>

<div class="ui divider"></div>

<div class="ui grid">
<div class="row">
<div class="ui twelve wide column">
<div class="ui sixteen wide column">
<div class="ui two column stackable grid">
<div class="column">
<h2>{{.i18n.Tr "dataset.dir"}}</h2>
<div class="ui divider"></div>
<div class="ui grid">
<div class="row">
<div class="ui twelve wide column">
<div class="ui sixteen wide column">
<div class="ui two column stackable grid">
<div class="column">
<h2>{{.i18n.Tr "dataset.dir"}}</h2>
</div>
</div>
</div>
<div class="dir list">
{{template "repo/datasets/dirs/dir_list" .}}
</div>
</div>
</div>
</div>
<div class="dir list">
{{template "repo/datasets/dirs/dir_list" .}}
</div>
</div>
</form>
</div>



{{template "base/footer" .}}

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

@@ -1130,17 +1130,6 @@ 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')
}).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