Skip to content

Commit

Permalink
Merge pull request #94 from oss-slu/Issue#62
Browse files Browse the repository at this point in the history
File path handling in search query input on /temp route Fixes (#62)
  • Loading branch information
SiriChandanaGarimella authored Nov 4, 2024
2 parents da38fde + 1991918 commit 27eb448
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions client-app/src/components/DraftOrcaDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../styles/TempComponent.css";

const DraftOrcaDashboard = () => {
const [selectedFile, setSelectedFile] = useState(null);
const [fileName, setFileName] = useState("");
const [filePath, setFilePath] = useState("");
const [searchTerms, setSearchTerms] = useState([]);
const [specifyLines, setSpecifyLines] = useState([]);
const [sections, setSections] = useState([]);
Expand All @@ -24,7 +24,6 @@ const DraftOrcaDashboard = () => {
return;
}
setSelectedFile(selectedFile);
setFileName(selectedFile.name.split("/").pop());
};

const isSearchQueryEnabled = () => {
Expand Down Expand Up @@ -76,18 +75,18 @@ const DraftOrcaDashboard = () => {
axios
.post("http://localhost:5001/upload", formData)
.then((response) => {
const uploadedFileName = response.data.filename.split("/").pop();
setFileName(uploadedFileName);
const uploadedFileName = response.data.file_name;
setFilePath(response.data.file_path);
setUploadedFiles((prevUploadedFiles) => [...prevUploadedFiles, uploadedFileName]);
})
.catch((error) => {
console.error("Error uploading file:", error);
});
};

const removeUploadedFile = (fileName) => {
const removeUploadedFile = (filePath) => {
// You can add logic here to delete the file from the server if needed
setUploadedFiles((prevUploadedFiles) => prevUploadedFiles.filter((file) => file !== fileName));
setUploadedFiles((prevUploadedFiles) => prevUploadedFiles.filter((file) => file !== filePath));
};

const onSubmit = () => {
Expand All @@ -97,7 +96,7 @@ const DraftOrcaDashboard = () => {
}

const data = {
file_path: fileName.toString(),
file_path: filePath.toString(),
search_terms: searchTerms,
sections: sections,
specify_lines: specifyLines.join(","),
Expand Down
6 changes: 4 additions & 2 deletions server/usecases/upload_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def file_upload_use_case(file):
return ResponseFailure(ResponseTypes.PARAMETER_ERROR, 'Invalid file type')

try:
filename = save_uploaded_file(file)
return ResponseSuccess({'message': 'Success', 'filename': filename})
file_path = save_uploaded_file(file)
file_name = file.filename
return ResponseSuccess({'message': 'Success', 'file_name': file_name,
'file_path': file_path})
except PermissionError as e:
return ResponseFailure(ResponseTypes.PARAMETER_ERROR, f'Permission denied: {str(e)}')
except FileNotFoundError as e:
Expand Down

0 comments on commit 27eb448

Please sign in to comment.