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

Refs https://github.com/1Panel-dev/1Panel/issues/2895
This commit is contained in:
zhengkunwang 2023-12-04 14:56:09 +08:00 committed by GitHub
parent 9658ebdfdb
commit d60338f350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 184 additions and 13 deletions

View File

@ -68,3 +68,19 @@ func (b *BaseApi) ClearRecycleBinFile(c *gin.Context) {
} }
helper.SuccessWithOutData(c) 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)
}

View File

@ -50,6 +50,8 @@ type SettingInfo struct {
AppStoreVersion string `json:"appStoreVersion"` AppStoreVersion string `json:"appStoreVersion"`
AppStoreLastModified string `json:"appStoreLastModified"` AppStoreLastModified string `json:"appStoreLastModified"`
AppStoreSyncStatus string `json:"appStoreSyncStatus"` AppStoreSyncStatus string `json:"appStoreSyncStatus"`
FileRecycleBin string `json:"fileRecycleBin"`
} }
type SettingUpdate struct { type SettingUpdate struct {

View File

@ -136,6 +136,10 @@ func (f *FileService) Create(op request.FileCreate) error {
func (f *FileService) Delete(op request.FileDelete) error { func (f *FileService) Delete(op request.FileDelete) error {
fo := files.NewFileOp() fo := files.NewFileOp()
recycleBinStatus, _ := settingRepo.Get(settingRepo.WithByKey("FileRecycleBin"))
if recycleBinStatus.Value == "disable" {
op.ForceDelete = true
}
if op.ForceDelete { if op.ForceDelete {
if op.IsDir { if op.IsDir {
return fo.DeleteDir(op.Path) return fo.DeleteDir(op.Path)

View File

@ -59,6 +59,7 @@ func Init() {
migrations.AddDockerSockPath, migrations.AddDockerSockPath,
migrations.AddDatabaseSSL, migrations.AddDatabaseSSL,
migrations.AddDefaultCA, migrations.AddDefaultCA,
migrations.AddSettingRecycleBin,
}) })
if err := m.Migrate(); err != nil { if err := m.Migrate(); err != nil {
global.LOG.Error(err) global.LOG.Error(err)

View File

@ -77,3 +77,13 @@ var AddDefaultCA = &gormigrate.Migration{
return nil 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
},
}

View File

@ -43,6 +43,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) {
fileRouter.POST("/recycle/search", baseApi.SearchRecycleBinFile) fileRouter.POST("/recycle/search", baseApi.SearchRecycleBinFile)
fileRouter.POST("/recycle/reduce", baseApi.ReduceRecycleBinFile) fileRouter.POST("/recycle/reduce", baseApi.ReduceRecycleBinFile)
fileRouter.POST("/recycle/clear", baseApi.ClearRecycleBinFile) fileRouter.POST("/recycle/clear", baseApi.ClearRecycleBinFile)
fileRouter.GET("/recycle/status", baseApi.GetRecycleStatus)
fileRouter.POST("/favorite/search", baseApi.SearchFavorite) fileRouter.POST("/favorite/search", baseApi.SearchFavorite)
fileRouter.POST("/favorite", baseApi.CreateFavorite) fileRouter.POST("/favorite", baseApi.CreateFavorite)

View File

@ -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 package docs
import "github.com/swaggo/swag" import "github.com/swaggo/swag"
@ -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": { "/files/rename": {
"post": { "post": {
"security": [ "security": [
@ -13506,6 +13528,9 @@ const docTemplate = `{
"names" "names"
], ],
"properties": { "properties": {
"force": {
"type": "boolean"
},
"names": { "names": {
"type": "array", "type": "array",
"items": { "items": {
@ -16822,6 +16847,9 @@ const docTemplate = `{
"expirationTime": { "expirationTime": {
"type": "string" "type": "string"
}, },
"fileRecycleBin": {
"type": "string"
},
"ipv6": { "ipv6": {
"type": "string" "type": "string"
}, },
@ -19035,6 +19063,9 @@ const docTemplate = `{
"autoRenew": { "autoRenew": {
"type": "boolean" "type": "boolean"
}, },
"description": {
"type": "string"
},
"dir": { "dir": {
"type": "string" "type": "string"
}, },
@ -19652,6 +19683,9 @@ const docTemplate = `{
"certificatePath": { "certificatePath": {
"type": "string" "type": "string"
}, },
"description": {
"type": "string"
},
"privateKey": { "privateKey": {
"type": "string" "type": "string"
}, },

View File

@ -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": { "/files/rename": {
"post": { "post": {
"security": [ "security": [
@ -13499,6 +13521,9 @@
"names" "names"
], ],
"properties": { "properties": {
"force": {
"type": "boolean"
},
"names": { "names": {
"type": "array", "type": "array",
"items": { "items": {
@ -16815,6 +16840,9 @@
"expirationTime": { "expirationTime": {
"type": "string" "type": "string"
}, },
"fileRecycleBin": {
"type": "string"
},
"ipv6": { "ipv6": {
"type": "string" "type": "string"
}, },
@ -19028,6 +19056,9 @@
"autoRenew": { "autoRenew": {
"type": "boolean" "type": "boolean"
}, },
"description": {
"type": "string"
},
"dir": { "dir": {
"type": "string" "type": "string"
}, },
@ -19645,6 +19676,9 @@
"certificatePath": { "certificatePath": {
"type": "string" "type": "string"
}, },
"description": {
"type": "string"
},
"privateKey": { "privateKey": {
"type": "string" "type": "string"
}, },

View File

@ -95,6 +95,8 @@ definitions:
type: object type: object
dto.BatchDelete: dto.BatchDelete:
properties: properties:
force:
type: boolean
names: names:
items: items:
type: string type: string
@ -2334,6 +2336,8 @@ definitions:
type: string type: string
expirationTime: expirationTime:
type: string type: string
fileRecycleBin:
type: string
ipv6: ipv6:
type: string type: string
language: language:
@ -3808,6 +3812,8 @@ definitions:
properties: properties:
autoRenew: autoRenew:
type: boolean type: boolean
description:
type: string
dir: dir:
type: string type: string
domains: domains:
@ -4227,6 +4233,8 @@ definitions:
type: string type: string
certificatePath: certificatePath:
type: string type: string
description:
type: string
privateKey: privateKey:
type: string type: string
privateKeyPath: privateKeyPath:
@ -8522,6 +8530,19 @@ paths:
summary: List RecycleBin files summary: List RecycleBin files
tags: tags:
- File - File
/files/recycle/status:
get:
consumes:
- application/json
description: 获取回收站状态
responses:
"200":
description: OK
security:
- ApiKeyAuth: []
summary: Get RecycleBin status
tags:
- File
/files/rename: /files/rename:
post: post:
consumes: consumes:

View File

@ -120,3 +120,7 @@ export const RemoveFavorite = (id: number) => {
export const BatchChangeRole = (params: File.FileRole) => { export const BatchChangeRole = (params: File.FileRole) => {
return http.post<any>('files/batch/role', params); return http.post<any>('files/batch/role', params);
}; };
export const GetRecycleStatus = () => {
return http.get<string>('files/recycle/status');
};

View File

@ -88,7 +88,7 @@ export const Rewrites = [
'typecho', 'typecho',
'typecho2', 'typecho2',
'thinkphp', 'thinkphp',
'yii2', 'yii2',
'laravel5', 'laravel5',
'discuz', 'discuz',
'discuzx', 'discuzx',

View File

@ -1087,6 +1087,8 @@ const message = {
deleteRecycleHelper: 'Are you sure you want to permanently delete the following files?', deleteRecycleHelper: 'Are you sure you want to permanently delete the following files?',
typeErrOrEmpty: '[{0}] file type is wrong or empty folder', typeErrOrEmpty: '[{0}] file type is wrong or empty folder',
dropHelper: 'Drag the files you want to upload here', dropHelper: 'Drag the files you want to upload here',
fileRecycleBin: 'File Recycle Bin',
fileRecycleBinMsg: '{0} recycle bin',
}, },
ssh: { ssh: {
autoStart: 'Auto Start', autoStart: 'Auto Start',

View File

@ -1036,6 +1036,8 @@ const message = {
deleteRecycleHelper: '確定永久刪除以下文件', deleteRecycleHelper: '確定永久刪除以下文件',
typeErrOrEmpty: '{0} 檔案類型錯誤或為空資料夾', typeErrOrEmpty: '{0} 檔案類型錯誤或為空資料夾',
dropHelper: '將需要上傳的文件拖曳到此處', dropHelper: '將需要上傳的文件拖曳到此處',
fileRecycleBin: '檔案回收站',
fileRecycleBinMsg: '{0}回收站',
}, },
ssh: { ssh: {
autoStart: '開機自啟', autoStart: '開機自啟',

View File

@ -1037,6 +1037,8 @@ const message = {
deleteRecycleHelper: '确定永久删除以下文件', deleteRecycleHelper: '确定永久删除以下文件',
typeErrOrEmpty: '{0} 文件类型错误或为空文件夹', typeErrOrEmpty: '{0} 文件类型错误或为空文件夹',
dropHelper: '将需要上传的文件拖曳到此处', dropHelper: '将需要上传的文件拖曳到此处',
fileRecycleBin: '文件回收站',
fileRecycleBinMsg: '{0}回收站',
}, },
ssh: { ssh: {
autoStart: '开机自启', autoStart: '开机自启',

View File

@ -8,7 +8,7 @@
<span>{{ $t('file.deleteHelper') }}</span> <span>{{ $t('file.deleteHelper') }}</span>
</div> </div>
</el-alert> </el-alert>
<div class="mt-4"> <div class="mt-4" v-if="recycleStatus === 'enable'">
<el-checkbox v-model="forceDelete">{{ $t('file.forceDeleteHelper') }}</el-checkbox> <el-checkbox v-model="forceDelete">{{ $t('file.forceDeleteHelper') }}</el-checkbox>
</div> </div>
<div class="file-list"> <div class="file-list">
@ -49,7 +49,7 @@ import i18n from '@/lang';
import { ref } from 'vue'; import { ref } from 'vue';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { getIcon } from '@/utils/util'; import { getIcon } from '@/utils/util';
import { DeleteFile } from '@/api/modules/files'; import { DeleteFile, GetRecycleStatus } from '@/api/modules/files';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
const open = ref(false); const open = ref(false);
@ -57,13 +57,25 @@ const files = ref();
const loading = ref(false); const loading = ref(false);
const em = defineEmits(['close']); const em = defineEmits(['close']);
const forceDelete = ref(false); const forceDelete = ref(false);
const recycleStatus = ref('enable');
const acceptParams = (props: File.File[]) => { const acceptParams = (props: File.File[]) => {
getStatus();
files.value = props; files.value = props;
open.value = true; open.value = true;
forceDelete.value = false; 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 onConfirm = () => {
const pros = []; const pros = [];
for (const s of files.value) { for (const s of files.value) {
@ -98,8 +110,9 @@ defineExpose({
} }
.file-list { .file-list {
height: 400px; max-height: 400px;
overflow-y: auto; overflow-y: auto;
margin-top: 15px;
} }
.delete-warn { .delete-warn {

View File

@ -3,12 +3,17 @@
<template #header> <template #header>
<DrawerHeader :header="$t('file.recycleBin')" :back="handleClose" /> <DrawerHeader :header="$t('file.recycleBin')" :back="handleClose" />
</template> </template>
<el-button @click="clear" type="primary" :disabled="data == null || data.length == 0"> <div class="flex space-x-4">
{{ $t('file.clearRecycleBin') }} <el-button @click="clear" type="primary" :disabled="data == null || data.length == 0">
</el-button> {{ $t('file.clearRecycleBin') }}
<el-button @click="patchDelete" :disabled="data == null || selects.length == 0"> </el-button>
{{ $t('commons.button.delete') }} <el-button @click="patchDelete" :disabled="data == null || selects.length == 0">
</el-button> {{ $t('commons.button.delete') }}
</el-button>
<el-form-item :label="$t('file.fileRecycleBin')">
<el-switch v-model="status" active-value="enable" inactive-value="disable" @change="changeStatus" />
</el-form-item>
</div>
<ComplexTable <ComplexTable
:pagination-config="paginationConfig" :pagination-config="paginationConfig"
v-model:selects="selects" v-model:selects="selects"
@ -46,11 +51,13 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { clearRecycle, getRecycleList, reduceFile } from '@/api/modules/files'; import { GetRecycleStatus, clearRecycle, getRecycleList, reduceFile } from '@/api/modules/files';
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { dateFormat, computeSize } from '@/utils/util'; import { dateFormat, computeSize } from '@/utils/util';
import i18n from '@/lang'; import i18n from '@/lang';
import Delete from './delete/index.vue'; import Delete from './delete/index.vue';
import { updateSetting } from '@/api/modules/setting';
import { MsgSuccess } from '@/utils/message';
const open = ref(false); const open = ref(false);
const req = reactive({ const req = reactive({
@ -62,6 +69,7 @@ const em = defineEmits(['close']);
const selects = ref([]); const selects = ref([]);
const loading = ref(false); const loading = ref(false);
const files = ref([]); const files = ref([]);
const status = ref('enable');
const paginationConfig = reactive({ const paginationConfig = reactive({
cacheSizeKey: 'recycle-page-size', cacheSizeKey: 'recycle-page-size',
@ -83,6 +91,23 @@ const getFileSize = (size: number) => {
const acceptParams = () => { const acceptParams = () => {
search(); search();
getStatus();
};
const getStatus = async () => {
try {
const res = await GetRecycleStatus();
status.value = res.data;
} catch (error) {}
};
const changeStatus = async () => {
try {
loading.value = true;
await updateSetting({ key: 'FileRecycleBin', value: status.value });
MsgSuccess(i18n.global.t('file.fileRecycleBinMsg', [i18n.global.t('commons.button.' + status.value)]));
loading.value = false;
} catch (error) {}
}; };
const search = async () => { const search = async () => {