diff --git a/agent/app/dto/container.go b/agent/app/dto/container.go index 69dbc9de9285..b69295ca6066 100644 --- a/agent/app/dto/container.go +++ b/agent/app/dto/container.go @@ -209,11 +209,12 @@ type NetworkCreate struct { } type Volume struct { - Name string `json:"name"` - Labels []string `json:"labels"` - Driver string `json:"driver"` - Mountpoint string `json:"mountpoint"` - CreatedAt time.Time `json:"createdAt"` + Name string `json:"name"` + Labels []VolumeOption `json:"labels"` + Driver string `json:"driver"` + Mountpoint string `json:"mountpoint"` + CreatedAt time.Time `json:"createdAt"` + Options []VolumeOption `json:"options"` } type VolumeCreate struct { Name string `json:"name" validate:"required"` @@ -221,7 +222,10 @@ type VolumeCreate struct { Options []string `json:"options"` Labels []string `json:"labels"` } - +type VolumeOption struct { + Key string `json:"key"` + Value string `json:"value"` +} type BatchDelete struct { TaskID string `json:"taskID"` Force bool `json:"force"` diff --git a/agent/app/service/container_volume.go b/agent/app/service/container_volume.go index e9fcf389cd69..0443361dc473 100644 --- a/agent/app/service/container_volume.go +++ b/agent/app/service/container_volume.go @@ -5,6 +5,7 @@ import ( "sort" "strings" "time" + "unicode" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/buserr" @@ -53,25 +54,27 @@ func (u *ContainerService) PageVolume(req dto.SearchWithPage) (int64, interface{ nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) for _, item := range records { - tag := make([]string, 0) - for _, val := range item.Labels { - tag = append(tag, val) + var volume dto.Volume + volume.Driver = item.Driver + volume.Mountpoint = item.Mountpoint + volume.Name = simplifyVolumeName(item.Name) + for key, val := range item.Labels { + volume.Labels = append(volume.Labels, dto.VolumeOption{Key: key, Value: val}) } - var createTime time.Time + for key, val := range item.Options { + volume.Options = append(volume.Options, dto.VolumeOption{Key: key, Value: val}) + } + sort.Slice(volume.Options, func(i, j int) bool { + return volume.Options[i].Key < volume.Options[j].Key + }) if strings.Contains(item.CreatedAt, "Z") { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05Z", item.CreatedAt, nyc) + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05Z", item.CreatedAt, nyc) } else if strings.Contains(item.CreatedAt, "+") { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05+08:00", item.CreatedAt, nyc) + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05+08:00", item.CreatedAt, nyc) } else { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05", item.CreatedAt, nyc) + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05", item.CreatedAt, nyc) } - data = append(data, dto.Volume{ - CreatedAt: createTime, - Name: item.Name, - Driver: item.Driver, - Mountpoint: item.Mountpoint, - Labels: tag, - }) + data = append(data, volume) } return int64(total), data, nil @@ -140,3 +143,16 @@ func (u *ContainerService) CreateVolume(req dto.VolumeCreate) error { } return nil } + +func simplifyVolumeName(name string) string { + if len(name) != 64 { + return name + } + + for _, char := range name { + if !unicode.Is(unicode.ASCII_Hex_Digit, char) { + return name + } + } + return name[:12] +} diff --git a/frontend/src/views/container/volume/index.vue b/frontend/src/views/container/volume/index.vue index ed982a488841..0b99175f580f 100644 --- a/frontend/src/views/container/volume/index.vue +++ b/frontend/src/views/container/volume/index.vue @@ -47,15 +47,35 @@ - + + > + + { taskLogRef.value.openWithTaskID(taskID); }; +const jumpTo = async (path: any) => { + await checkFile(path, false).then((res) => { + if (res.data) { + routerToFileWithPath(path); + } else { + MsgError(i18n.global.t('file.noSuchFile')); + } + }); +}; + const batchDelete = async (row: Container.VolumeInfo | null) => { let names = []; if (row) {