|
|
|
@@ -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) |
|
|
|
} |