diff --git a/src/__tests__/__snapshots__/storybook.test.ts.snap b/src/__tests__/__snapshots__/storybook.test.ts.snap index 13864097..e089a3f5 100644 --- a/src/__tests__/__snapshots__/storybook.test.ts.snap +++ b/src/__tests__/__snapshots__/storybook.test.ts.snap @@ -54,7 +54,7 @@ Array [ onKeyDown={[Function]} >
-
Files that would be overwritten: @@ -90,7 +80,7 @@ Array [ onKeyDown={[Function]} >
`; diff --git a/src/background/api/filesystem.ts b/src/background/api/filesystem.ts index f141f995..48fadea0 100644 --- a/src/background/api/filesystem.ts +++ b/src/background/api/filesystem.ts @@ -15,14 +15,14 @@ const fhHostname = constants.url.FH_URL; export const getFolderContents = (path: string) => { console.log("[Get folder content", path) - return new Promise((resolve, reject) => { + return new Promise>((resolve, reject) => { let config = { headers: { "X-FF-PATH": path } }; Axios.get(hostname + filesystemPath + "contents", config) - .then((response: AxiosResponse) => resolve(response.data)) + .then((response: AxiosResponse) => resolve(response)) .catch((error) => reject(error)); }) } @@ -32,7 +32,6 @@ export const uploadPreflight = ( files: File[] | EditableFileWithPreflightInfo[], parentFolderID: string ): Promise => { - parentFolderID = "0" //TODO const postData = files.map((f: File | EditableFileWithPreflightInfo) => ({ // @ts-ignore name: f.newName ?? f.name, @@ -54,7 +53,6 @@ export const uploadPreflight = ( }; export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], parentFolderID: string) => { - parentFolderID = "0"; //TODO console.log("[API filesystem] uploading files to folderID", parentFolderID , files); const apiCall = (file: File | EditableFileWithPreflightInfo) => { return new Promise((resolve, reject) => { @@ -94,27 +92,7 @@ export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], par }; handleMultipleApiActions(files, apiCall, ApiActionType.UPLOAD); }; -/* -export const downloadFiles = (files : FsEntity[]) => { - Axios.get(fhHostname + "/download", { - responseType: "blob", // Important - headers: { - "Content-Type": "multipart/form-data", - "X-FF-IDS": files.map((e:FsEntity) => e.fileSystemId).toString() - }, - onDownloadProgress(progress) { - //console.log("download progress:", progress); - } - }).then((response) => { - // fileDownload(response.data, "bild.png"); - const url = window.URL.createObjectURL(new Blob([response.data])); - const link = document.createElement("a"); - link.href = url; - link.setAttribute("download", "file.pdf"); - document.body.appendChild(link); - link.click(); - }); -};*/ + export const deleteFsEntities = (files: FsEntity[]) => { const apiCall = (fsEntity: FsEntity) => { diff --git a/src/background/constants.ts b/src/background/constants.ts index 3d8e4871..1a65fcfe 100644 --- a/src/background/constants.ts +++ b/src/background/constants.ts @@ -16,7 +16,8 @@ const dev: constantsdef = { // API_URL: "http://localhost:8080", //API_URL: "http://localhost/api", //FH_URL: "http://localhost:5000/data" - FH_URL: "http://localhost/data" + //FH_URL: "http://localhost/data" + FH_URL: "https://demo.filefighter.de/data" } }; diff --git a/src/background/methods/filesystem.ts b/src/background/methods/filesystem.ts index 8dd2d5bb..943c2017 100644 --- a/src/background/methods/filesystem.ts +++ b/src/background/methods/filesystem.ts @@ -4,12 +4,12 @@ export const getPathWithoutName = ( pathWithName: string, name: string ): string => { - return pathWithName.substr(0, pathWithName.lastIndexOf(name)); + return pathWithName.substr(0, pathWithName.lastIndexOf(name.toLowerCase())); }; export const removeTrailingBackslash = (path : string): string => { - if (path.lastIndexOf("/") === path.length){ + if (path.lastIndexOf("/") +1 === path.length){ return path.substr(0,path.length -1) } return path diff --git a/src/background/redux/reducers/filesystem.ts b/src/background/redux/reducers/filesystem.ts index b945a820..9f10f66f 100644 --- a/src/background/redux/reducers/filesystem.ts +++ b/src/background/redux/reducers/filesystem.ts @@ -16,7 +16,7 @@ import {FsEntity} from "../../api/filesystemTypes"; const initialState: FilesystemState = { selectedFsEntities: [], folderContents: [], - currentFsItemId: "", + currentFsItemId: "-1", currentPath: "" }; diff --git a/src/components/pages/filesytem/FileList.tsx b/src/components/pages/filesytem/FileList.tsx index be8e21da..40bc80c1 100644 --- a/src/components/pages/filesytem/FileList.tsx +++ b/src/components/pages/filesytem/FileList.tsx @@ -10,6 +10,7 @@ import {SystemState} from "../../../background/redux/actions/sytemState"; import {addToSelected, clearSelected, removeFromSelected, replaceSelected, setContents, setCurrentFsItemId, setCurrentPath} from "../../../background/redux/actions/filesystem"; import {connect, ConnectedProps} from "react-redux"; import {FFLoading} from "../../basicElements/Loading"; +import {AxiosResponse} from "axios"; const mapState = (state: SystemState) => ({ filesystem: { @@ -61,17 +62,17 @@ function FileList(props: Props): ReactElement { useEffect(() => { function updateStates(): void { getFolderContents(path) - .then((response: FsEntity[]) => { - console.log("got folder content"); + .then((response: AxiosResponse) => { + console.log("got folder content",response); setContents([ - ...response.filter( + ...response.data.filter( (fsEntity: FsEntity) => fsEntity.type === "FOLDER" ), - ...response.filter((fsEntity: FsEntity) => fsEntity.type !== "FOLDER") + ...response.data.filter((fsEntity: FsEntity) => fsEntity.type !== "FOLDER") ]); setError(""); - setCurrentFsItemId(path); // TODO change this to the id of the current folder + setCurrentFsItemId(response.headers["x-ff-current"]); }) .catch((err) => { setError(err.response?.data?.message); @@ -139,7 +140,7 @@ function FileList(props: Props): ReactElement { setFilesAndFolders(sortIncreasing ? toSort.reverse() : toSort); } - console.log("[FileList path]" + path); + console.log("[FileList path]" + path, filesAndFolders); return ( diff --git a/src/components/pages/filesytem/upload/UploadDecisionsModalContent.stories.tsx b/src/components/pages/filesytem/upload/UploadDecisionsModalContent.stories.tsx index d855f70f..74ac2cc4 100644 --- a/src/components/pages/filesytem/upload/UploadDecisionsModalContent.stories.tsx +++ b/src/components/pages/filesytem/upload/UploadDecisionsModalContent.stories.tsx @@ -53,10 +53,18 @@ storiesOf("Filesystem", module).add("UploadDecisionsModal", () => { { name: "blubfdhjsgfhj---fsd/", path: "fasel/blubfdhjsgfhj---fsd/", - permissionIsSufficient: false, - nameAlreadyInUse: true, + permissionIsSufficient: true, + nameAlreadyInUse: false, nameIsValid: false, isFile: false + }, + { + name: "notAllowed", + path: "fasel/notAllowed", + permissionIsSufficient: false, + nameAlreadyInUse: false, + nameIsValid: true, + isFile: false } ]; diff --git a/src/components/pages/filesytem/upload/UploadDecisionsModalContent.tsx b/src/components/pages/filesytem/upload/UploadDecisionsModalContent.tsx index 854b0e62..341aa542 100644 --- a/src/components/pages/filesytem/upload/UploadDecisionsModalContent.tsx +++ b/src/components/pages/filesytem/upload/UploadDecisionsModalContent.tsx @@ -55,7 +55,7 @@ export const UploadDecisionsModalContent = ({ setPreflightResultDispatch({ type: PREFLIGHT_ADD_ENTITIES, payload: combined }); } else { uploadFiles(combined.filter( - (f: EditablePreflightEntityOrFile) => !f.isFile) as EditableFileWithPreflightInfo[], fsItemIdToUpload); + (f: EditablePreflightEntityOrFile) => f.isFile) as EditableFileWithPreflightInfo[], fsItemIdToUpload); handleClose(); setPreflightResultDispatch({ type: PREFLIGHT_ADD_ENTITIES, payload: [] }); } @@ -63,6 +63,13 @@ export const UploadDecisionsModalContent = ({ }); }; + const handleOverWriteAll = () => { + uploadFiles(preflightResult.filter( + (f: EditablePreflightEntityOrFile) => f.isFile) as EditableFileWithPreflightInfo[], fsItemIdToUpload); + handleClose(); + setPreflightResultDispatch({ type: PREFLIGHT_ADD_ENTITIES, payload: [] }); + } + const foldersToMerge = preflightResult.filter( (f: EditablePreflightEntityOrFile) => !f.isFile && f.nameAlreadyInUse ); @@ -80,7 +87,7 @@ export const UploadDecisionsModalContent = ({ return ( {files.map((f: EditablePreflightEntityOrFile) => ( - {f.path} + {f.path} ))} ); @@ -158,12 +165,12 @@ export const UploadDecisionsModalContent = ({ Cancel
-