Skip to content

Commit

Permalink
Working bin parser + front end
Browse files Browse the repository at this point in the history
  • Loading branch information
gr812b committed Apr 19, 2024
1 parent cc93f5d commit 5f28e06
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<FileInformation> getInformationForFolder(@PathParam("folderkey") Str

List<FileInformation> fileInformationList = storageService.loadAll(targetPath)
.map(path -> new FileInformation(
path.toString().replace("\\", "/"),
targetPath.relativize(path).toString(),
fileMetadataService.readHeaders(path),
path.toFile().lastModified()
))
Expand Down
19 changes: 8 additions & 11 deletions backend/src/main/java/com/mcmasterbaja/FileUploadResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,23 @@ public Response uploadFile(@MultipartForm FileUploadForm form) {
break;

case "bin":
fileName = fileName.substring(4, fileName.length() - 4) + "/";
logger.info("File name: " + fileName);
fileName = fileName.substring(4, fileName.length());

//storageService.store(form.fileData, Paths.get(fileName));

logger.info("Absolute location: " + storageService.getRootLocation().resolve(fileName).toString() + "/");

//logger.info("Bytes: " + form.fileData.readAllBytes().length);
logger.info("Parsing bin to: "
+ storageService.getRootLocation().resolve("csv").toString()
+ "/"
+ fileName.substring(0, fileName.lastIndexOf('.'))
+ "/");

try {
BinaryToCSV.bytesToCSV(
form.fileData.readAllBytes(),
storageService.getRootLocation().resolve(fileName).toString() + "/",
storageService.getRootLocation().resolve(fileName).toString(),
storageService.getRootLocation().resolve("csv/").toString(),
fileName,
true);
} catch (UnsatisfiedLinkError e) {
return Response.serverError().entity("File upload failed: " + e.getMessage()).build();
}

//storageService.delete(Paths.get(fileName));
break;

case "mov":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class BinaryToCSV {

static {
String path = System.getProperty("user.dir");
path += relativePath + "/binary_to_csv_lib.dll";
System.out.println("PATH " + path);
path += relativePath + "/libbinary_to_csv_lib.dylib";
// System.out.println("PATH " + path);
System.load(path);
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DefaultFileMetadataService implements FileMetadataService {

public String[] readHeaders(Path targetPath) {
try {
logger.info("Reading headers from: " + targetPath);
// logger.info("Reading headers from: " + targetPath);
return Files.lines(storageService.getRootLocation().resolve(targetPath)).findFirst().get().split(",");
} catch (IOException e) {
logger.error("Could not read headers", e);
Expand Down
10 changes: 5 additions & 5 deletions binary-to-csv-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,18 @@ pub extern "system" fn Java_com_mcmasterbaja_binary_1csv_BinaryToCSV_bytesToCSV<
let mut utilised_types: HashMap<DataType, BufWriter<std::fs::File>> =
HashMap::with_capacity(DATA_TYPE_LEN);
let extension_index = file_name.find('.').unwrap();
let path_no_extension = &file_name[0..extension_index];
let path_no_extension = destination.to_string() + "/" + &file_name[0..extension_index];
if folder {
match std::fs::create_dir(path_no_extension) {
match std::fs::create_dir(&path_no_extension) {
Ok(_) => println!("Created folder: {}", path_no_extension),
Err(e) => {
if e.kind() == std::io::ErrorKind::AlreadyExists {
println!(
"Folder already exists: {}\nAttempting to delete and reparse",
path_no_extension
);
std::fs::remove_dir_all(path_no_extension).unwrap();
std::fs::create_dir(path_no_extension).unwrap();
std::fs::remove_dir_all(&path_no_extension).unwrap();
std::fs::create_dir(&path_no_extension).unwrap();
} else {
panic!("{}", e);
}
Expand All @@ -473,7 +473,7 @@ pub extern "system" fn Java_com_mcmasterbaja_binary_1csv_BinaryToCSV_bytesToCSV<

for packet in parsed_packets {
utilised_types.entry(packet.datatype).or_insert_with(|| {
get_writer(&packet.datatype, &destination, path_no_extension, folder)
get_writer(&packet.datatype, &destination, &path_no_extension, folder)
});

match packet.datatype {
Expand Down
1 change: 1 addition & 0 deletions front-end/src/components/modal/FileStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RawFileBrowser, { Icons } from 'react-keyed-file-browser';
import React from 'react';

const formatSize = (size) => {
if (size === 0) return '0 B';
// Finds the order of magnitude of the size in base 1024 (e.g. how many digits it would have)
const magnitude = Math.floor(Math.log(size) / Math.log(1024));
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'ZB', 'YB', 'RB', 'QB'];
Expand Down
10 changes: 8 additions & 2 deletions front-end/src/lib/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export const ApiUtil = {
},

/**
* @description Sends a GET request to the server to fetch a specific folder.
* @description Sends a GET request to the server to fetch fileInformation about a specific folder.
* Each file in the list is represented as an object with the following properties:
* - key: A that represents the unique identifier of the file. This will be relative to the folder provided.
* - fileHeaders: An array of strings that represents the headers of the file.
* - size: A long that represents the size of the file.
*
* @param {string} folderKey - The unique identifier of the folder.
* @returns {Promise<Response>} A promise that resolves to the server's response.
*/
Expand Down Expand Up @@ -134,7 +139,8 @@ export const ApiUtil = {
*/
uploadFile: async (file) => {
const formData = new FormData();
formData.set('file', file);
formData.set('fileName', file.name);
formData.set('fileData', file);

const response = await fetch(`http://${window.location.hostname}:8080/upload/file`, {
method: 'POST',
Expand Down

0 comments on commit 5f28e06

Please sign in to comment.