Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加回收站开关功能 #3161

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/app/api/v1/recycle_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ func (b *BaseApi) ClearRecycleBinFile(c *gin.Context) {
}
helper.SuccessWithOutData(c)
}

// @Tags File
// @Summary Get RecycleBin status
// @Description 获取回收站状态
// @Accept json
// @Success 200
// @Security ApiKeyAuth
// @Router /files/recycle/status [get]
func (b *BaseApi) GetRecycleStatus(c *gin.Context) {
settingInfo, err := settingService.GetSettingInfo()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, settingInfo.FileRecycleBin)
}
2 changes: 2 additions & 0 deletions backend/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type SettingInfo struct {
AppStoreVersion string `json:"appStoreVersion"`
AppStoreLastModified string `json:"appStoreLastModified"`
AppStoreSyncStatus string `json:"appStoreSyncStatus"`

FileRecycleBin string `json:"fileRecycleBin"`
}

type SettingUpdate struct {
Expand Down
4 changes: 4 additions & 0 deletions backend/app/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (f *FileService) Create(op request.FileCreate) error {

func (f *FileService) Delete(op request.FileDelete) error {
fo := files.NewFileOp()
recycleBinStatus, _ := settingRepo.Get(settingRepo.WithByKey("FileRecycleBin"))
if recycleBinStatus.Value == "disable" {
op.ForceDelete = true
}
if op.ForceDelete {
if op.IsDir {
return fo.DeleteDir(op.Path)
Expand Down
1 change: 1 addition & 0 deletions backend/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Init() {
migrations.AddDockerSockPath,
migrations.AddDatabaseSSL,
migrations.AddDefaultCA,
migrations.AddSettingRecycleBin,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
10 changes: 10 additions & 0 deletions backend/init/migration/migrations/v_1_9.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ var AddDefaultCA = &gormigrate.Migration{
return nil
},
}

var AddSettingRecycleBin = &gormigrate.Migration{
ID: "20231129-add-setting-recycle-bin",
Migrate: func(tx *gorm.DB) error {
if err := tx.Create(&model.Setting{Key: "FileRecycleBin", Value: "enable"}).Error; err != nil {
return err
}
return nil
},
}
1 change: 1 addition & 0 deletions backend/router/ro_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) {
fileRouter.POST("/recycle/search", baseApi.SearchRecycleBinFile)
fileRouter.POST("/recycle/reduce", baseApi.ReduceRecycleBinFile)
fileRouter.POST("/recycle/clear", baseApi.ClearRecycleBinFile)
fileRouter.GET("/recycle/status", baseApi.GetRecycleStatus)

fileRouter.POST("/favorite/search", baseApi.SearchFavorite)
fileRouter.POST("/favorite", baseApi.CreateFavorite)
Expand Down
38 changes: 36 additions & 2 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -5919,6 +5919,28 @@ const docTemplate = `{
}
}
},
"/files/recycle/status": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取回收站状态",
"consumes": [
"application/json"
],
"tags": [
"File"
],
"summary": "Get RecycleBin status",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/files/rename": {
"post": {
"security": [
Expand Down Expand Up @@ -13506,6 +13528,9 @@ const docTemplate = `{
"names"
],
"properties": {
"force": {
"type": "boolean"
},
"names": {
"type": "array",
"items": {
Expand Down Expand Up @@ -16822,6 +16847,9 @@ const docTemplate = `{
"expirationTime": {
"type": "string"
},
"fileRecycleBin": {
"type": "string"
},
"ipv6": {
"type": "string"
},
Expand Down Expand Up @@ -19035,6 +19063,9 @@ const docTemplate = `{
"autoRenew": {
"type": "boolean"
},
"description": {
"type": "string"
},
"dir": {
"type": "string"
},
Expand Down Expand Up @@ -19652,6 +19683,9 @@ const docTemplate = `{
"certificatePath": {
"type": "string"
},
"description": {
"type": "string"
},
"privateKey": {
"type": "string"
},
Expand Down
34 changes: 34 additions & 0 deletions cmd/server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,28 @@
}
}
},
"/files/recycle/status": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取回收站状态",
"consumes": [
"application/json"
],
"tags": [
"File"
],
"summary": "Get RecycleBin status",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/files/rename": {
"post": {
"security": [
Expand Down Expand Up @@ -13499,6 +13521,9 @@
"names"
],
"properties": {
"force": {
"type": "boolean"
},
"names": {
"type": "array",
"items": {
Expand Down Expand Up @@ -16815,6 +16840,9 @@
"expirationTime": {
"type": "string"
},
"fileRecycleBin": {
"type": "string"
},
"ipv6": {
"type": "string"
},
Expand Down Expand Up @@ -19028,6 +19056,9 @@
"autoRenew": {
"type": "boolean"
},
"description": {
"type": "string"
},
"dir": {
"type": "string"
},
Expand Down Expand Up @@ -19645,6 +19676,9 @@
"certificatePath": {
"type": "string"
},
"description": {
"type": "string"
},
"privateKey": {
"type": "string"
},
Expand Down
21 changes: 21 additions & 0 deletions cmd/server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ definitions:
type: object
dto.BatchDelete:
properties:
force:
type: boolean
names:
items:
type: string
Expand Down Expand Up @@ -2334,6 +2336,8 @@ definitions:
type: string
expirationTime:
type: string
fileRecycleBin:
type: string
ipv6:
type: string
language:
Expand Down Expand Up @@ -3808,6 +3812,8 @@ definitions:
properties:
autoRenew:
type: boolean
description:
type: string
dir:
type: string
domains:
Expand Down Expand Up @@ -4227,6 +4233,8 @@ definitions:
type: string
certificatePath:
type: string
description:
type: string
privateKey:
type: string
privateKeyPath:
Expand Down Expand Up @@ -8522,6 +8530,19 @@ paths:
summary: List RecycleBin files
tags:
- File
/files/recycle/status:
get:
consumes:
- application/json
description: 获取回收站状态
responses:
"200":
description: OK
security:
- ApiKeyAuth: []
summary: Get RecycleBin status
tags:
- File
/files/rename:
post:
consumes:
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/api/modules/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ export const RemoveFavorite = (id: number) => {
export const BatchChangeRole = (params: File.FileRole) => {
return http.post<any>('files/batch/role', params);
};

export const GetRecycleStatus = () => {
return http.get<string>('files/recycle/status');
};
2 changes: 1 addition & 1 deletion frontend/src/global/mimetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Rewrites = [
'typecho',
'typecho2',
'thinkphp',
'yii2',
'yii2',
'laravel5',
'discuz',
'discuzx',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ const message = {
deleteRecycleHelper: 'Are you sure you want to permanently delete the following files?',
typeErrOrEmpty: '[{0}] file type is wrong or empty folder',
dropHelper: 'Drag the files you want to upload here',
fileRecycleBin: 'File Recycle Bin',
fileRecycleBinMsg: '{0} recycle bin',
},
ssh: {
autoStart: 'Auto Start',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ const message = {
deleteRecycleHelper: '確定永久刪除以下文件?',
typeErrOrEmpty: '【{0}】 檔案類型錯誤或為空資料夾',
dropHelper: '將需要上傳的文件拖曳到此處',
fileRecycleBin: '檔案回收站',
fileRecycleBinMsg: '已{0}回收站',
},
ssh: {
autoStart: '開機自啟',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ const message = {
deleteRecycleHelper: '确定永久删除以下文件?',
typeErrOrEmpty: '【{0}】 文件类型错误或为空文件夹',
dropHelper: '将需要上传的文件拖曳到此处',
fileRecycleBin: '文件回收站',
fileRecycleBinMsg: '已{0}回收站',
},
ssh: {
autoStart: '开机自启',
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/views/host/file-management/delete/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span>{{ $t('file.deleteHelper') }}</span>
</div>
</el-alert>
<div class="mt-4">
<div class="mt-4" v-if="recycleStatus === 'enable'">
<el-checkbox v-model="forceDelete">{{ $t('file.forceDeleteHelper') }}</el-checkbox>
</div>
<div class="file-list">
Expand Down Expand Up @@ -49,21 +49,33 @@ import i18n from '@/lang';
import { ref } from 'vue';
import { File } from '@/api/interface/file';
import { getIcon } from '@/utils/util';
import { DeleteFile } from '@/api/modules/files';
import { DeleteFile, GetRecycleStatus } from '@/api/modules/files';
import { MsgSuccess } from '@/utils/message';

const open = ref(false);
const files = ref();
const loading = ref(false);
const em = defineEmits(['close']);
const forceDelete = ref(false);
const recycleStatus = ref('enable');

const acceptParams = (props: File.File[]) => {
getStatus();
files.value = props;
open.value = true;
forceDelete.value = false;
};

const getStatus = async () => {
try {
const res = await GetRecycleStatus();
recycleStatus.value = res.data;
if (recycleStatus.value === 'disable') {
forceDelete.value = true;
}
} catch (error) {}
};

const onConfirm = () => {
const pros = [];
for (const s of files.value) {
Expand Down Expand Up @@ -98,8 +110,9 @@ defineExpose({
}

.file-list {
height: 400px;
max-height: 400px;
overflow-y: auto;
margin-top: 15px;
}

.delete-warn {
Expand Down
Loading
Loading