mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 14:31:44 +01:00
fix: fixes broken download link when host name has :
This commit is contained in:
@@ -169,7 +169,7 @@ const downloadParams = computed(() =>
|
||||
|
||||
const downloadUrl = computed(() =>
|
||||
withBase(
|
||||
`/api/containers/${container.host}:${container.id}/download?${new URLSearchParams(downloadParams.value).toString()}`,
|
||||
`/api/containers/${container.host}~${container.id}/download?${new URLSearchParams(downloadParams.value).toString()}`,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ const downloadParams = computed(() =>
|
||||
|
||||
const downloadUrl = computed(() =>
|
||||
withBase(
|
||||
`/api/containers/${containers.value.map((c) => c.host + ":" + c.id).join(",")}/download?${new URLSearchParams(downloadParams.value).toString()}`,
|
||||
`/api/containers/${containers.value.map((c) => c.host + "~" + c.id).join(",")}/download?${new URLSearchParams(downloadParams.value).toString()}`,
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
@@ -12,11 +12,13 @@ import (
|
||||
"github.com/amir20/dozzle/internal/docker"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
hostIds := strings.Split(chi.URLParam(r, "hostIds"), ",")
|
||||
if len(hostIds) == 0 {
|
||||
log.Error().Msg("no container ids provided")
|
||||
http.Error(w, "no container ids provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -55,8 +57,9 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Process each container
|
||||
for _, hostId := range hostIds {
|
||||
parts := strings.Split(hostId, ":")
|
||||
parts := strings.Split(hostId, "~")
|
||||
if len(parts) != 2 {
|
||||
log.Error().Msgf("invalid host id: %s", hostId)
|
||||
http.Error(w, fmt.Sprintf("invalid host id: %s", hostId), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -65,6 +68,7 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
id := parts[1]
|
||||
containerService, err := h.multiHostService.FindContainer(host, id, usersFilter)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("error finding container %s", id)
|
||||
http.Error(w, fmt.Sprintf("error finding container %s: %v", id, err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -73,6 +77,7 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
fileName := fmt.Sprintf("%s-%s.log", containerService.Container.Name, nowFmt)
|
||||
f, err := zw.Create(fileName)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("error creating zip entry for container %s", id)
|
||||
http.Error(w, fmt.Sprintf("error creating zip entry: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -80,6 +85,7 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
// Get container logs
|
||||
reader, err := containerService.RawLogs(r.Context(), time.Time{}, now, stdTypes)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("error getting logs for container %s", id)
|
||||
http.Error(w, fmt.Sprintf("error getting logs for container %s: %v", id, err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -87,11 +93,13 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
// Copy logs directly to zip entry
|
||||
if containerService.Container.Tty {
|
||||
if _, err := io.Copy(f, reader); err != nil {
|
||||
log.Error().Err(err).Msgf("error copying logs for container %s", id)
|
||||
http.Error(w, fmt.Sprintf("error copying logs for container %s: %v", id, err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err := stdcopy.StdCopy(f, f, reader); err != nil {
|
||||
log.Error().Err(err).Msgf("error copying logs for container %s", id)
|
||||
http.Error(w, fmt.Sprintf("error copying logs for container %s: %v", id, err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
func Test_handler_download_logs(t *testing.T) {
|
||||
id := "123456"
|
||||
req, err := http.NewRequest("GET", "/api/containers/localhost:"+id+"/download?stdout=1", nil)
|
||||
req, err := http.NewRequest("GET", "/api/containers/localhost~"+id+"/download?stdout=1", nil)
|
||||
require.NoError(t, err, "NewRequest should not return an error.")
|
||||
|
||||
mockedClient := new(MockedClient)
|
||||
|
||||
Reference in New Issue
Block a user