From 0d3e834b37b1b37297edc3d65c90dbb25ca01ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:13:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E7=9C=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E8=A7=A3=E9=99=A4=E4=BA=8C=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=99=90=E5=88=B6=20(#5696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/request/file.go | 3 ++- backend/app/service/file.go | 5 +++-- backend/utils/files/fileinfo.go | 9 +++++++-- frontend/src/api/interface/file.ts | 1 + frontend/src/views/host/file-management/detail/index.vue | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/app/dto/request/file.go b/backend/app/dto/request/file.go index 0e61d41f5..96c771dab 100644 --- a/backend/app/dto/request/file.go +++ b/backend/app/dto/request/file.go @@ -10,7 +10,8 @@ type FileOption struct { } type FileContentReq struct { - Path string `json:"path" validate:"required"` + Path string `json:"path" validate:"required"` + IsDetail bool `json:"isDetail"` } type SearchUploadWithPage struct { diff --git a/backend/app/service/file.go b/backend/app/service/file.go index 6feda1a5e..1581609ec 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -288,8 +288,9 @@ func (f *FileService) DeCompress(c request.FileDeCompress) error { func (f *FileService) GetContent(op request.FileContentReq) (response.FileInfo, error) { info, err := files.NewFileInfo(files.FileOption{ - Path: op.Path, - Expand: true, + Path: op.Path, + Expand: true, + IsDetail: op.IsDetail, }) if err != nil { return response.FileInfo{}, err diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go index 224e95296..ebe027d63 100644 --- a/backend/utils/files/fileinfo.go +++ b/backend/utils/files/fileinfo.go @@ -44,6 +44,7 @@ type FileInfo struct { Items []*FileInfo `json:"items"` ItemTotal int `json:"itemTotal"` FavoriteID uint `json:"favoriteID"` + IsDetail bool `json:"isDetail"` } type FileOption struct { @@ -57,6 +58,7 @@ type FileOption struct { PageSize int `json:"pageSize"` SortBy string `json:"sortBy"` SortOrder string `json:"sortOrder"` + IsDetail bool `json:"isDetail"` } type FileSearchInfo struct { @@ -89,6 +91,7 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { Gid: strconv.FormatUint(uint64(info.Sys().(*syscall.Stat_t).Gid), 10), Group: GetGroup(info.Sys().(*syscall.Stat_t).Gid), MimeType: GetMimeType(op.Path), + IsDetail: op.IsDetail, } favoriteRepo := repo.NewIFavoriteRepo() favorite, _ := favoriteRepo.GetFirst(favoriteRepo.WithByPath(op.Path)) @@ -322,8 +325,10 @@ func (f *FileInfo) getContent() error { if err != nil { return nil } - if len(cByte) > 0 && DetectBinary(cByte) { - return buserr.New(constant.ErrFileCanNotRead) + if !f.IsDetail { + if len(cByte) > 0 && DetectBinary(cByte) { + return buserr.New(constant.ErrFileCanNotRead) + } } f.Content = string(cByte) return nil diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index 7110b1692..7329c9667 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -33,6 +33,7 @@ export namespace File { containSub?: boolean; sortBy?: string; sortOrder?: string; + isDetail?: boolean; } export interface SearchUploadInfo extends ReqPage { diff --git a/frontend/src/views/host/file-management/detail/index.vue b/frontend/src/views/host/file-management/detail/index.vue index 1d397842d..d10d907b3 100644 --- a/frontend/src/views/host/file-management/detail/index.vue +++ b/frontend/src/views/host/file-management/detail/index.vue @@ -56,7 +56,7 @@ const handleClose = () => { const acceptParams = async (params: InfoProps): Promise => { props.value = params; - GetFileContent({ path: params.path, expand: false, page: 1, pageSize: 1 }).then((res) => { + GetFileContent({ path: params.path, expand: false, page: 1, pageSize: 1, isDetail: true }).then((res) => { data.value = res.data; open.value = true; });