diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 9faaca360..f7a7d7ab1 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -1,12 +1,11 @@ package service import ( - "bytes" "context" "encoding/json" "fmt" - "io" "io/ioutil" + "os/exec" "sort" "strconv" "strings" @@ -20,7 +19,6 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" - "github.com/docker/docker/pkg/stdcopy" "github.com/docker/go-connections/nat" v1 "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -221,32 +219,15 @@ func (u *ContainerService) ContainerOperation(req dto.ContainerOperation) error } func (u *ContainerService) ContainerLogs(req dto.ContainerLog) (string, error) { - var ( - options types.ContainerLogsOptions - logs io.ReadCloser - buf *bytes.Buffer - err error - ) - client, err := docker.NewDockerClient() + cmd := exec.Command("docker", "logs", req.ContainerID) + if req.Mode != "all" { + cmd = exec.Command("docker", "logs", req.ContainerID, "--since", req.Mode) + } + stdout, err := cmd.CombinedOutput() if err != nil { return "", err } - options = types.ContainerLogsOptions{ - ShowStdout: true, - Timestamps: true, - } - if req.Mode != "all" { - options.Since = req.Mode - } - if logs, err = client.ContainerLogs(context.Background(), req.ContainerID, options); err != nil { - return "", err - } - defer logs.Close() - buf = new(bytes.Buffer) - if _, err = stdcopy.StdCopy(buf, nil, logs); err != nil { - return "", err - } - return buf.String(), nil + return string(stdout), nil } func (u *ContainerService) ContainerStats(id string) (*dto.ContainterStats, error) { diff --git a/frontend/src/views/container/container/log/index.vue b/frontend/src/views/container/container/log/index.vue index 19380ea7f..19c283f91 100644 --- a/frontend/src/views/container/container/log/index.vue +++ b/frontend/src/views/container/container/log/index.vue @@ -72,19 +72,19 @@ const timeOptions = ref([ { label: i18n.global.t('container.all'), value: 'all' }, { label: i18n.global.t('container.lastDay'), - value: new Date(new Date().getTime() - 3600 * 1000 * 24 * 1).getTime() / 1000 + '', + value: '24h', }, { label: i18n.global.t('container.last4Hour'), - value: new Date(new Date().getTime() - 3600 * 1000 * 4).getTime() / 1000 + '', + value: '4h', }, { label: i18n.global.t('container.lastHour'), - value: new Date(new Date().getTime() - 3600 * 1000).getTime() / 1000 + '', + value: '1h', }, { label: i18n.global.t('container.last10Min'), - value: new Date(new Date().getTime() - 600 * 1000).getTime() / 1000 + '', + value: '10m', }, ]); diff --git a/frontend/src/views/setting/panel/index.vue b/frontend/src/views/setting/panel/index.vue index ede0a7404..17e8164fd 100644 --- a/frontend/src/views/setting/panel/index.vue +++ b/frontend/src/views/setting/panel/index.vue @@ -73,7 +73,7 @@ @@ -125,7 +125,7 @@ import { ref, reactive, onMounted, computed } from 'vue'; import { ElForm, ElMessageBox } from 'element-plus'; import LayoutContent from '@/layout/layout-content.vue'; import { syncTime, getSettingInfo, updateSetting } from '@/api/modules/setting'; -import { Rules } from '@/global/form-rules'; +import { Rules, checkNumberRange } from '@/global/form-rules'; import { GlobalStore } from '@/store'; import { useI18n } from 'vue-i18n'; import { useTheme } from '@/hooks/use-theme'; diff --git a/frontend/src/views/setting/safe/index.vue b/frontend/src/views/setting/safe/index.vue index 091d8883f..1aafb9596 100644 --- a/frontend/src/views/setting/safe/index.vue +++ b/frontend/src/views/setting/safe/index.vue @@ -114,7 +114,7 @@ - + {{ $t('setting.expirationHelper') }} @@ -139,7 +139,7 @@ import LayoutContent from '@/layout/layout-content.vue'; import DrawerHeader from '@/components/drawer-header/index.vue'; import { updateSetting, getMFA, bindMFA, getSettingInfo, updatePort } from '@/api/modules/setting'; import i18n from '@/lang'; -import { Rules } from '@/global/form-rules'; +import { Rules, checkNumberRange } from '@/global/form-rules'; import { dateFormatSimple } from '@/utils/util'; import { MsgError, MsgSuccess } from '@/utils/message';