Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/src/main/java/cloudpage/dto/FileDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class FileDto {
private String path;
private long size;
private String mimeType;
private long lastModifiedAt;
}
7 changes: 4 additions & 3 deletions backend/src/main/java/cloudpage/dto/FolderDto.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cloudpage.dto;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
Expand All @@ -14,4 +14,5 @@ public class FolderDto {
private String path;
private List<FolderDto> folders;
private List<FileDto> files;
}
private long lastModifiedAt;
}
32 changes: 22 additions & 10 deletions backend/src/main/java/cloudpage/service/FolderService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package cloudpage.service;

import cloudpage.dto.FileDto;
import cloudpage.dto.FolderDto;
import cloudpage.exceptions.FileDeletionException;
import cloudpage.exceptions.InvalidPathException;
import cloudpage.exceptions.UnauthorizedAccessException;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -16,6 +9,13 @@
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import cloudpage.dto.FileDto;
import cloudpage.dto.FolderDto;
import cloudpage.exceptions.FileDeletionException;
import cloudpage.exceptions.InvalidPathException;

@Service
public class FolderService {

Expand Down Expand Up @@ -82,15 +82,27 @@ private FolderDto readFolder(Path path) throws IOException {
filePath.getFileName().toString(),
filePath.toAbsolutePath().toString(),
attrs.size(),
Files.probeContentType(filePath)
Files.probeContentType(filePath),
attrs.lastModifiedTime().toMillis()
);
} catch (IOException e) {
throw new FileDeletionException("Failed to read: " + filePath + "with exception : " + e.getMessage());
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before 'with exception'. Should be 'with exception :' (note: this is a pre-existing issue that also affects line 71).

Copilot uses AI. Check for mistakes.
Copy link
Member

@DenizAltunkapan DenizAltunkapan Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this, also in Line 71 as Copilot mentioned.

}
})
.collect(Collectors.toList());

return new FolderDto(path.getFileName().toString(), path.toAbsolutePath().toString(), subfolders, files);
try {
BasicFileAttributes folderAttrs = Files.readAttributes(path, BasicFileAttributes.class);
return new FolderDto(
path.getFileName().toString(),
path.toAbsolutePath().toString(),
subfolders,
files,
folderAttrs.lastModifiedTime().toMillis()
);
} catch (IOException e) {
throw new FileDeletionException("Failed to read folder attributes: " + path + " with exception: " + e.getMessage());
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using FileDeletionException for a read operation is misleading. This exception should only be used for deletion failures. Consider creating a new exception type like FileReadException or use a more generic exception like RuntimeException with a descriptive message.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

public void validatePath(String rootPath, Path path) {
Expand All @@ -104,4 +116,4 @@ private void validateRoot(Path root) {
throw new InvalidPathException("Root folder does not exist or is not a directory: " + root);
}
}
}
}
Loading