Skip to content

Commit

Permalink
feat: 查看文件详情解除二进制文件限制 (#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
lan-yonghui committed Jul 5, 2024
1 parent 2e84033 commit 0d3e834
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion backend/app/dto/request/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions backend/app/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions backend/utils/files/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/interface/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export namespace File {
containSub?: boolean;
sortBy?: string;
sortOrder?: string;
isDetail?: boolean;
}

export interface SearchUploadInfo extends ReqPage {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/host/file-management/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const handleClose = () => {
const acceptParams = async (params: InfoProps): Promise<void> => {
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;
});
Expand Down

0 comments on commit 0d3e834

Please sign in to comment.