Skip to content

Commit 53b1a7a

Browse files
authored
feat: Copy and move files with the same name file processing (#7871)
1 parent 078d7fb commit 53b1a7a

File tree

10 files changed

+157
-9
lines changed

10 files changed

+157
-9
lines changed

frontend/src/lang/modules/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ const message = {
13741374
existFileTitle: 'Same name file prompt',
13751375
existFileHelper: 'The uploaded file contains a file with the same name, do you want to overwrite it?',
13761376
existFileSize: 'File size (new -> old)',
1377+
existFileDirHelper: 'The selected file/folder has a duplicate name. Please proceed with caution!',
13771378
},
13781379
ssh: {
13791380
setting: 'Setting',

frontend/src/lang/modules/ja.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ const message = {
13521352
existFileTitle: '同名ファイルの警告',
13531353
existFileHelper: 'アップロードしたファイルに同じ名前のファイルが含まれています。上書きしますか?',
13541354
existFileSize: 'ファイルサイズ(新しい -> 古い)',
1355+
existFileDirHelper: '選択したファイル/フォルダーには同じ名前のものが既に存在します。慎重に操作してください!',
13551356
},
13561357
ssh: {
13571358
setting: '設定',

frontend/src/lang/modules/ko.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ const message = {
13381338
existFileTitle: '동일한 이름의 파일 경고',
13391339
existFileHelper: '업로드한 파일에 동일한 이름의 파일이 포함되어 있습니다. 덮어쓰시겠습니까?',
13401340
existFileSize: '파일 크기 (새로운 -> 오래된)',
1341+
existFileDirHelper: '선택한 파일/폴더에 동일한 이름이 이미 존재합니다. 신중하게 작업하세요!',
13411342
},
13421343
ssh: {
13431344
setting: '설정',

frontend/src/lang/modules/ms.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ const message = {
13941394
existFileTitle: 'Amaran fail dengan nama yang sama',
13951395
existFileHelper: 'Fail yang dimuat naik mengandungi fail dengan nama yang sama. Adakah anda mahu menimpanya?',
13961396
existFileSize: 'Saiz fail (baru -> lama)',
1397+
existFileDirHelper: 'Fail/folder yang dipilih mempunyai nama yang sama. Sila berhati-hati!',
13971398
},
13981399
ssh: {
13991400
setting: 'tetapan',

frontend/src/lang/modules/pt-br.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ const message = {
13811381
existFileTitle: 'Aviso de arquivo com o mesmo nome',
13821382
existFileHelper: 'O arquivo enviado contém um arquivo com o mesmo nome. Deseja substituí-lo?',
13831383
existFileSize: 'Tamanho do arquivo (novo -> antigo)',
1384+
existFileDirHelper: 'O arquivo/pasta selecionado tem um nome duplicado. Por favor, prossiga com cautela!',
13841385
},
13851386
ssh: {
13861387
setting: 'configuração',

frontend/src/lang/modules/ru.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ const message = {
13841384
existFileTitle: 'Предупреждение о файле с тем же именем',
13851385
existFileHelper: 'Загруженный файл содержит файл с таким же именем. Заменить его?',
13861386
existFileSize: 'Размер файла (новый -> старый)',
1387+
existFileDirHelper: 'Выбранный файл/папка имеет дублирующееся имя. Пожалуйста, действуйте осторожно!',
13871388
},
13881389
ssh: {
13891390
setting: 'настройка',

frontend/src/lang/modules/tw.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ const message = {
13091309
existFileTitle: '同名檔案提示',
13101310
existFileHelper: '上傳的檔案存在同名檔案,是否覆蓋?',
13111311
existFileSize: '文件大小(新->舊)',
1312+
existFileDirHelper: '選擇的檔案/資料夾存在同名,請謹慎操作!',
13121313
},
13131314
ssh: {
13141315
setting: '設定',

frontend/src/lang/modules/zh.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ const message = {
13111311
existFileTitle: '同名文件提示',
13121312
existFileHelper: '上传的文件存在同名文件,是否覆盖?',
13131313
existFileSize: '文件大小 (新 -> 旧)',
1314+
existFileDirHelper: '选择的文件/文件夹存在同名,请谨慎操作!',
13141315
},
13151316
ssh: {
13161317
setting: '配置',

frontend/src/views/host/file-management/index.vue

+14-4
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
549549
const fileUpload = reactive({ path: '' });
550550
const fileRename = reactive({ path: '', oldName: '' });
551551
const fileWget = reactive({ path: '' });
552-
const fileMove = reactive({ oldPaths: [''], type: '', path: '', name: '', count: 0 });
552+
const fileMove = reactive({ oldPaths: [''], allNames: [''], type: '', path: '', name: '', count: 0, isDir: false });
553553
const processPage = reactive({ open: false });
554554
555555
const createRef = ref();
@@ -961,14 +961,23 @@ const openRename = (item: File.File) => {
961961
const openMove = (type: string) => {
962962
fileMove.type = type;
963963
fileMove.name = '';
964-
const oldpaths = [];
964+
fileMove.allNames = [];
965+
fileMove.isDir = false;
966+
const oldPaths = [];
965967
for (const s of selects.value) {
966-
oldpaths.push(s['path']);
968+
oldPaths.push(s['path']);
967969
}
968970
fileMove.count = selects.value.length;
969-
fileMove.oldPaths = oldpaths;
971+
fileMove.oldPaths = oldPaths;
970972
if (selects.value.length == 1) {
971973
fileMove.name = selects.value[0].name;
974+
fileMove.isDir = selects.value[0].isDir;
975+
} else {
976+
const allNames = [];
977+
for (const s of selects.value) {
978+
allNames.push(s['name']);
979+
}
980+
fileMove.allNames = allNames;
972981
}
973982
moveOpen.value = true;
974983
};
@@ -979,6 +988,7 @@ const closeMove = () => {
979988
fileMove.oldPaths = [];
980989
fileMove.name = '';
981990
fileMove.count = 0;
991+
fileMove.isDir = false;
982992
moveOpen.value = false;
983993
};
984994

frontend/src/views/host/file-management/move/index.vue

+135-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:destroy-on-close="true"
55
:close-on-click-modal="false"
66
:close-on-press-escape="false"
7-
size="40%"
7+
size="675"
88
>
99
<template #header>
1010
<DrawerHeader :header="title" :back="handleClose" />
@@ -33,6 +33,23 @@
3333
<el-radio :value="false" size="large">{{ $t('file.rename') }}</el-radio>
3434
</el-radio-group>
3535
</div>
36+
<div v-if="existFiles.length > 0 && !changeName" class="text-center">
37+
<el-alert :show-icon="true" type="warning" :closable="false">
38+
<div class="whitespace-break-spaces">
39+
<span>{{ $t('file.existFileDirHelper') }}</span>
40+
</div>
41+
</el-alert>
42+
<el-transfer
43+
v-model="skipFiles"
44+
class="text-left inline-block mt-4"
45+
:titles="[$t('commons.button.cover'), $t('commons.button.skip')]"
46+
:format="{
47+
noChecked: '${total}',
48+
hasChecked: '${checked}/${total}',
49+
}"
50+
:data="transferData"
51+
/>
52+
</div>
3653
</el-form>
3754
</el-col>
3855
</el-row>
@@ -48,21 +65,23 @@
4865
</template>
4966

5067
<script lang="ts" setup>
51-
import { CheckFile, MoveFile } from '@/api/modules/files';
68+
import { BatchCheckFiles, CheckFile, MoveFile } from '@/api/modules/files';
5269
import { Rules } from '@/global/form-rules';
5370
import i18n from '@/lang';
5471
import { FormInstance, FormRules } from 'element-plus';
55-
import { ref, reactive, computed } from 'vue';
72+
import { ref, reactive, computed, ComputedRef } from 'vue';
5673
import FileList from '@/components/file-list/index.vue';
5774
import DrawerHeader from '@/components/drawer-header/index.vue';
5875
import { MsgSuccess } from '@/utils/message';
5976
import { getDateStr } from '@/utils/util';
6077
6178
interface MoveProps {
6279
oldPaths: Array<string>;
80+
allNames: Array<string>;
6381
type: string;
6482
path: string;
6583
name: string;
84+
isDir: boolean;
6685
}
6786
6887
const fileForm = ref<FormInstance>();
@@ -71,6 +90,9 @@ const open = ref(false);
7190
const type = ref('cut');
7291
const changeName = ref(false);
7392
const oldName = ref('');
93+
const existFiles = ref([]);
94+
const skipFiles = ref([]);
95+
const transferData = ref([]);
7496
7597
const title = computed(() => {
7698
if (type.value === 'cut') {
@@ -85,6 +107,8 @@ const addForm = reactive({
85107
newPath: '',
86108
type: '',
87109
name: '',
110+
allNames: [] as string[],
111+
isDir: false,
88112
cover: false,
89113
});
90114
@@ -103,6 +127,18 @@ const handleClose = (search: boolean) => {
103127
em('close', search);
104128
};
105129
130+
const getFileName = (filePath: string) => {
131+
if (filePath.endsWith('/')) {
132+
filePath = filePath.slice(0, -1);
133+
}
134+
135+
return filePath.split('/').pop();
136+
};
137+
138+
const coverFiles: ComputedRef<string[]> = computed(() => {
139+
return addForm.oldPaths.filter((item) => !skipFiles.value.includes(getFileName(item))).map((item) => item);
140+
});
141+
106142
const getPath = (path: string) => {
107143
addForm.newPath = path;
108144
};
@@ -111,7 +147,7 @@ const changeType = () => {
111147
if (addForm.cover) {
112148
addForm.name = oldName.value;
113149
} else {
114-
addForm.name = oldName.value + '-' + getDateStr();
150+
addForm.name = renameFileWithSuffix(oldName.value, addForm.isDir);
115151
}
116152
};
117153
@@ -137,24 +173,80 @@ const submit = async (formEl: FormInstance | undefined) => {
137173
return;
138174
}
139175
loading.value = true;
176+
addForm.oldPaths = coverFiles.value;
140177
mvFile();
141178
});
142179
};
143180
181+
const getCompleteExtension = (filename: string): string => {
182+
const compoundExtensions = [
183+
'.tar.gz',
184+
'.tar.bz2',
185+
'.tar.xz',
186+
'.tar.lzma',
187+
'.tar.Z',
188+
'.tar.zst',
189+
'.tar.lzo',
190+
'.tar.sz',
191+
'.tgz',
192+
'.tbz2',
193+
'.txz',
194+
'.tzst',
195+
];
196+
const foundExtension = compoundExtensions.find((ext) => filename.endsWith(ext));
197+
if (foundExtension) {
198+
return foundExtension;
199+
}
200+
const match = filename.match(/\.[a-zA-Z0-9]+$/);
201+
return match ? match[0] : '';
202+
};
203+
204+
const renameFileWithSuffix = (fileName: string, isDir: boolean): string => {
205+
const insertStr = '-' + getDateStr();
206+
const completeExt = isDir ? '' : getCompleteExtension(fileName);
207+
if (!completeExt) {
208+
return `${fileName}${insertStr}`;
209+
} else {
210+
const baseName = fileName.slice(0, fileName.length - completeExt.length);
211+
return `${baseName}${insertStr}${completeExt}`;
212+
}
213+
};
214+
215+
const handleFilePaths = async (fileNames: string[], newPath: string) => {
216+
const uniqueFiles = [...new Set(fileNames)];
217+
const fileNamesWithPath = uniqueFiles.map((file) => newPath + '/' + file);
218+
const existData = await BatchCheckFiles(fileNamesWithPath);
219+
existFiles.value = existData.data;
220+
transferData.value = existData.data.map((file) => ({
221+
key: file.name,
222+
label: file.name,
223+
}));
224+
};
225+
144226
const acceptParams = async (props: MoveProps) => {
145227
changeName.value = false;
146228
addForm.oldPaths = props.oldPaths;
147229
addForm.type = props.type;
148230
addForm.newPath = props.path;
231+
addForm.isDir = props.isDir;
149232
addForm.name = '';
233+
addForm.allNames = props.allNames;
150234
type.value = props.type;
151235
if (props.name && props.name != '') {
152236
oldName.value = props.name;
153237
const res = await CheckFile(props.path + '/' + props.name);
154238
if (res.data) {
155239
changeName.value = true;
156240
addForm.cover = false;
157-
addForm.name = props.name + '-' + getDateStr();
241+
addForm.name = renameFileWithSuffix(props.name, addForm.isDir);
242+
open.value = true;
243+
} else {
244+
mvFile();
245+
}
246+
} else if (props.allNames && props.allNames.length > 0) {
247+
await handleFilePaths(addForm.allNames, addForm.newPath);
248+
if (existFiles.value.length > 0) {
249+
changeName.value = false;
158250
open.value = true;
159251
} else {
160252
mvFile();
@@ -166,3 +258,41 @@ const acceptParams = async (props: MoveProps) => {
166258
167259
defineExpose({ acceptParams });
168260
</script>
261+
262+
<style lang="scss" scoped>
263+
:deep(.el-transfer) {
264+
--el-transfer-panel-width: 250px;
265+
.el-button {
266+
padding: 4px 7px;
267+
}
268+
}
269+
270+
:deep(.el-transfer__buttons) {
271+
padding: 5px 15px;
272+
@media (max-width: 600px) {
273+
width: 250px;
274+
text-align: center;
275+
padding: 10px 0;
276+
.el-button [class*='el-icon'] svg {
277+
transform: rotate(90deg);
278+
}
279+
}
280+
281+
@media (min-width: 601px) {
282+
display: inline-flex;
283+
flex-direction: column;
284+
align-items: center;
285+
gap: 10px;
286+
width: 40px;
287+
height: 40px;
288+
justify-content: center;
289+
.el-button + .el-button {
290+
margin-left: 0;
291+
}
292+
}
293+
}
294+
295+
:deep(.el-transfer-panel .el-transfer-panel__footer) {
296+
height: 65px;
297+
}
298+
</style>

0 commit comments

Comments
 (0)