Skip to content

Commit 4bfc91a

Browse files
committed
Fix mutation of directory name with slashes in it; closes pterodactyl#2377
1 parent 36eb048 commit 4bfc91a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

resources/scripts/components/server/files/NewDirectoryButton.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import Modal from '@/components/elements/Modal';
33
import { ServerContext } from '@/state/server';
44
import { Form, Formik, FormikHelpers } from 'formik';
@@ -12,6 +12,7 @@ import { FileObject } from '@/api/server/files/loadDirectory';
1212
import useFlash from '@/plugins/useFlash';
1313
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
1414
import { WithClassname } from '@/components/types';
15+
import FlashMessageRender from '@/components/FlashMessageRender';
1516

1617
interface Values {
1718
directoryName: string;
@@ -22,8 +23,8 @@ const schema = object().shape({
2223
});
2324

2425
const generateDirectoryData = (name: string): FileObject => ({
25-
key: `dir_${name}`,
26-
name: name,
26+
key: `dir_${name.split('/', 1)[0] ?? name}`,
27+
name: name.split('/', 1)[0] ?? name,
2728
mode: '0644',
2829
size: 0,
2930
isFile: false,
@@ -37,20 +38,28 @@ const generateDirectoryData = (name: string): FileObject => ({
3738

3839
export default ({ className }: WithClassname) => {
3940
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
40-
const { clearAndAddHttpError } = useFlash();
41+
const { clearFlashes, clearAndAddHttpError } = useFlash();
4142
const [ visible, setVisible ] = useState(false);
4243

4344
const { mutate } = useFileManagerSwr();
4445
const directory = ServerContext.useStoreState(state => state.files.directory);
4546

47+
useEffect(() => {
48+
if (visible) {
49+
return () => {
50+
clearFlashes('files:directory-modal');
51+
};
52+
}
53+
}, [ visible ]);
54+
4655
const submit = ({ directoryName }: Values, { setSubmitting }: FormikHelpers<Values>) => {
4756
createDirectory(uuid, directory, directoryName)
4857
.then(() => mutate(data => [ ...data, generateDirectoryData(directoryName) ], false))
4958
.then(() => setVisible(false))
5059
.catch(error => {
5160
console.error(error);
5261
setSubmitting(false);
53-
clearAndAddHttpError({ key: 'files', error });
62+
clearAndAddHttpError({ key: 'files:directory-modal', error });
5463
});
5564
};
5665

@@ -71,6 +80,7 @@ export default ({ className }: WithClassname) => {
7180
resetForm();
7281
}}
7382
>
83+
<FlashMessageRender key={'files:directory-modal'}/>
7484
<Form css={tw`m-0`}>
7585
<Field
7686
autoFocus

0 commit comments

Comments
 (0)