-
Notifications
You must be signed in to change notification settings - Fork 7
feat:add last-modified-at for both file and folder #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
@@ -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 { | ||
|
|
||
|
|
@@ -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()); | ||
| } | ||
| }) | ||
| .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()); | ||
|
||
| } | ||
| } | ||
|
|
||
| public void validatePath(String rootPath, Path path) { | ||
|
|
@@ -104,4 +116,4 @@ private void validateRoot(Path root) { | |
| throw new InvalidPathException("Root folder does not exist or is not a directory: " + root); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.