Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit f23b664

Browse files
authored
FF-423 add check if filename is valid before uploading of single file (#166)
* add check if filename is valid before uploading of single file * add videoUploadOnPasses to cypress config
1 parent 0274782 commit f23b664

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"baseUrl": "http://localhost:3000",
3-
"projectId": "57baod"
3+
"projectId": "57baod",
4+
"videoUploadOnPasses": false
45
}

src/background/methods/filesystem.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const getFileExtension = (fileName: string): string => {
2929
return reverseString(reverseString(fileName).substr(0, positionOfPoint));
3030
};
3131

32-
export const getMimeType = (fileName: string): string => {
33-
let positionOfFirstSlash = fileName.indexOf("/");
34-
return fileName.substr(0, positionOfFirstSlash);
35-
};
32+
export const isFileNameValid = (name: string) =>{
33+
return !(!name ||
34+
name.includes("/") ||
35+
name.match("[~#@*+:!?&%<>|\"^\\\\]"))
36+
}

src/components/pages/filesytem/ToolbarActions.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ function ToolbarActions(props: Props): ReactElement | null {
2121
deleteFsEntities(props.selectedFsEntities);
2222
}
2323

24-
/* function handleDownloadClicked() {
25-
downloadFiles(props.selectedFsEntities)
26-
} */
2724

2825
return (
2926
<span>

src/components/pages/filesytem/upload/UploadZone.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { uploadFiles, uploadPreflight } from "../../../../background/api/filesys
77
import { FsEntity } from "../../../../background/api/filesystemTypes";
88
import { UploadDecisionsModalContent } from "./UploadDecisionsModalContent";
99
import { divideArrayByCondition } from "../../../../background/methods/arrays";
10-
import { getPathWithoutName } from "../../../../background/methods/filesystem";
10+
import { getPathWithoutName, isFileNameValid } from "../../../../background/methods/filesystem";
1111
import {
1212
EditableEntityError,
1313
EditableFileWithPreflightInfo,
@@ -50,7 +50,7 @@ export const UploadZone = (): ReactElement => {
5050
let preflightNeeded = acceptedFiles.some(
5151
(file: EditablePreflightEntityOrFile) => {
5252
return (
53-
file.path.includes("/") ||
53+
file.path.includes("/") || !isFileNameValid(file.name) ||
5454
currentFsContent.some(
5555
(fsEntiy: FsEntity) => fsEntiy.name === file.name
5656
)
@@ -197,13 +197,9 @@ export const preflightResultReducer: Reducer<EditablePreflightEntityOrFile[],
197197
}
198198
);
199199

200-
let newNameIsValidNot =
201-
!action.payload.newName ||
202-
action.payload.newName.includes("/") ||
203-
action.payload.newName.includes(" ") ||
204-
action.payload.newName.match("[~#@*+:!?&%<>|\"^\\\\]");
200+
let newNameIsNotValid = !isFileNameValid(action.payload.newName)
205201

206-
if (newPathAlreadyExits || newNameIsValidNot) {
202+
if (newPathAlreadyExits || newNameIsNotValid) {
207203
elementToReplace.error = newPathAlreadyExits
208204
? EditableEntityError.ALREADYEXITS
209205
: EditableEntityError.INVALIDNAME;

0 commit comments

Comments
 (0)