You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dir.go 2.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package repo
  2. import (
  3. "errors"
  4. "io/ioutil"
  5. "path"
  6. "strings"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. )
  13. const (
  14. tplDirIndex base.TplName = "repo/datasets/dirs/index"
  15. )
  16. type FileInfo struct {
  17. FileName string
  18. ModTime string
  19. IsDir bool
  20. Size int64
  21. ParenDir string
  22. UUID string
  23. }
  24. func DirIndex(ctx *context.Context) {
  25. uuid := ctx.Params("uuid")
  26. parentDir := ctx.Query("parentDir")
  27. dirArray := strings.Split(parentDir, "/")
  28. if parentDir == "" {
  29. attachment, err := models.GetAttachmentByUUID(uuid)
  30. if err != nil {
  31. ctx.ServerError("GetDatasetAttachments", err)
  32. return
  33. }
  34. if !strings.HasSuffix(attachment.Name, ".zip") {
  35. log.Error("The file is not zip file, can not query the dir")
  36. 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"))
  37. return
  38. } else if attachment.DecompressState != models.DecompressStateDone {
  39. log.Error("The file has not been decompressed completely now")
  40. ctx.ServerError("The file has not been decompressed completely now", errors.New("The file has not been decompressed completely now"))
  41. return
  42. }
  43. // ctx.Data["OriginName"] = attachment.Name
  44. }
  45. files, err := ioutil.ReadDir(setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath +
  46. path.Join(uuid[0:1], uuid[1:2], uuid+uuid) + "/" + parentDir)
  47. if err != nil {
  48. log.Error("ReadDir failed:", err.Error())
  49. ctx.ServerError("ReadDir failed:", err)
  50. return
  51. }
  52. i := 1
  53. var fileInfos []FileInfo
  54. for _, file := range files {
  55. if i > 100 {
  56. break
  57. }
  58. log.Info(file.Name())
  59. var tmp string
  60. if parentDir == "" {
  61. tmp = file.Name()
  62. } else {
  63. tmp = parentDir + "/" + file.Name()
  64. }
  65. fileInfos = append(fileInfos, FileInfo{
  66. FileName: file.Name(),
  67. ModTime: file.ModTime().Format("2006-01-02 15:04:05"),
  68. IsDir: file.IsDir(),
  69. Size: file.Size(),
  70. ParenDir: tmp,
  71. UUID: uuid,
  72. })
  73. i++
  74. }
  75. ctx.Data["Path"] = dirArray
  76. ctx.Data["Dirs"] = fileInfos
  77. ctx.Data["PageIsDataset"] = true
  78. ctx.HTML(200, tplDirIndex)
  79. }