Conversation
There was a problem hiding this comment.
I don't think that its smart to save the files in the db.
Assume the Server changes => then the db must synchronize with the corresponding folder.
Cloud Page intentionally manages files stored on disk — introducing a JPA layer means the filesystem and database will quickly get out of sync.
|
|
||
| @GetMapping("/content") | ||
| public ResponseEntity<String> getFileContent(@RequestParam String path) throws IOException { | ||
| public ResponseEntity<?> getFileContent( |
There was a problem hiding this comment.
This method mixes two very different responsibilities — fetching file content (current design) vs paginated listing from a database (new behavior).
File listings should remain filesystem-based, not database-backed.
Pagination can be implemented in-memory by slicing the list of files in FolderService without persisting them.
| public ResponseEntity<?> listFilesForDownload( | ||
| @RequestParam(required = false) String path, | ||
| @RequestParam(defaultValue = "0") int pageNumber, | ||
| @RequestParam(defaultValue = "10") int pageSize, | ||
| @RequestParam(required = false) String sort) { | ||
|
|
||
| @GetMapping("/view") | ||
| public ResponseEntity<Resource> viewFile(@RequestParam String path) throws IOException { | ||
| var user = userService.getCurrentUser(); | ||
| Path fullPath = Paths.get(user.getRootFolderPath(), path).normalize(); | ||
| folderService.validatePath(user.getRootFolderPath(), fullPath); | ||
| Pageable pageable; | ||
| if (sort != null && !sort.isEmpty()) { | ||
| pageable = PageRequest.of(pageNumber, pageSize, Sort.by(sort)); | ||
| } else { | ||
| pageable = PageRequest.of(pageNumber, pageSize, Sort.by("fileId").descending()); | ||
| } | ||
|
|
||
| if (!fullPath.toFile().exists() || !fullPath.toFile().isFile()) { | ||
| throw new IllegalArgumentException("File does not exist: " + fullPath); | ||
| Page<File> filePage; | ||
|
|
||
| if (path == null || path.isEmpty()) { | ||
| filePage = fileRepository.findAllFiles(pageable); | ||
| } else { | ||
| filePage = fileRepository.searchAllFiles(pageable, path.toUpperCase()); | ||
| } | ||
|
|
||
| Resource resource = new UrlResource(fullPath.toUri()); | ||
| String mimeType = Files.probeContentType(fullPath); | ||
| if (mimeType == null) { | ||
| mimeType = "application/octet-stream"; | ||
| Map<String, Object> response = new HashMap<>(); | ||
| response.put("message", "File(s) available for download"); | ||
| response.put("status", "success"); | ||
| response.put("data", filePage.getContent()); | ||
| response.put("totalFiles", filePage.getTotalElements()); | ||
| response.put("totalPages", filePage.getTotalPages()); | ||
| response.put("currentPage", filePage.getNumber()); | ||
| response.put("code", 200); | ||
|
|
||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
|
|
||
| @GetMapping("/view") | ||
| public ResponseEntity<?> listFilesForView( |
There was a problem hiding this comment.
These endpoints currently return paginated JSON lists instead of serving actual files or file streams.
This completely changes the API semantics — /download should send the file as an attachment, /view should stream it.
There was a problem hiding this comment.
shouldn’t exist unless the project’s architecture explicitly shifts from filesystem-based storage to database-indexed file metadata.
| # PostgreSQL DB Connection | ||
| spring.datasource.username=postgres | ||
| spring.datasource.password=root | ||
| spring.datasource.password=12345 |
There was a problem hiding this comment.
Please don't push your password.
|
@hamadiddi Thank you for your contribution |
|
@hamadiddi still working on it? |
|
@DenizAltunkapan currently occupied, might do it later but not anytime soon. |
This pull request implements pagination support for the file and folder listing APIs. It introduces pageNumber, pageSize, and optional sort query parameters to allow clients to retrieve content in pages rather than loading the entire dataset at once.
Key changes include:
Updated /content, /download, /view, and root folder endpoints to support pagination.
Added response metadata: totalElements, totalPages, and currentPage.
Optional sorting for files.
Improved consistency and usability for large directories.