2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00
Files
panel/internal/service/container_image.go
Copilot 3d8623a9f9 feat: 添加容器终端功能 (#1216)
* Initial plan

* feat: 添加容器终端功能 - 通过 WebSocket 进入容器执行命令

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: 将 fmt.Errorf 错误信息改为英语

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* feat: 前端优化

* feat: 容器优化

* feat: 前端优化

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>
Co-authored-by: 耗子 <haozi@loli.email>
2026-01-11 05:30:52 +08:00

91 lines
2.0 KiB
Go

package service
import (
"net/http"
"github.com/libtnb/chix"
"github.com/acepanel/panel/internal/biz"
"github.com/acepanel/panel/internal/http/request"
)
type ContainerImageService struct {
containerImageRepo biz.ContainerImageRepo
}
func NewContainerImageService(containerImage biz.ContainerImageRepo) *ContainerImageService {
return &ContainerImageService{
containerImageRepo: containerImage,
}
}
func (s *ContainerImageService) List(w http.ResponseWriter, r *http.Request) {
images, err := s.containerImageRepo.List()
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
paged, total := Paginate(r, images)
Success(w, chix.M{
"total": total,
"items": paged,
})
}
func (s *ContainerImageService) Exist(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImagePull](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
exist, err := s.containerImageRepo.Exist(req.Name)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, exist)
}
func (s *ContainerImageService) Pull(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImagePull](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.containerImageRepo.Pull(req); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}
func (s *ContainerImageService) Remove(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImageID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.containerImageRepo.Remove(req.ID); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}
func (s *ContainerImageService) Prune(w http.ResponseWriter, r *http.Request) {
if err := s.containerImageRepo.Prune(); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}