Skip to content

Commit

Permalink
Merge branch 'patch-v8.10.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Feb 5, 2025
2 parents 2de7391 + 9ce736a commit 17c15b6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
10 changes: 9 additions & 1 deletion internal/web/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"github.com/amir20/dozzle/internal/container"
"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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -73,25 +77,29 @@ 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
}

// 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
}

// 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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/web/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dozzle",
"version": "8.10.5",
"version": "8.10.6",
"description": "Realtime log viewer for docker containers.",
"homepage": "https://github.com/amir20/dozzle#readme",
"bugs": {
Expand Down

0 comments on commit 17c15b6

Please sign in to comment.