Skip to content

Commit d6983f5

Browse files
committed
polish
1 parent 764134e commit d6983f5

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/main/java/org/joinfaces/docs/server/controller/FileController.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.joinfaces.docs.server.controller;
1818

1919
import jakarta.annotation.PostConstruct;
20-
import jakarta.servlet.http.HttpServletRequest;
2120
import lombok.extern.slf4j.Slf4j;
2221
import org.joinfaces.docs.server.DocsServerProperties;
2322
import org.joinfaces.docs.server.model.EntryInfo;
@@ -28,9 +27,9 @@
2827
import org.springframework.stereotype.Controller;
2928
import org.springframework.util.Assert;
3029
import org.springframework.web.bind.annotation.GetMapping;
30+
import org.springframework.web.bind.annotation.PathVariable;
3131
import org.springframework.web.context.request.WebRequest;
3232
import org.springframework.web.server.ResponseStatusException;
33-
import org.springframework.web.servlet.HandlerMapping;
3433
import org.springframework.web.servlet.ModelAndView;
3534
import org.springframework.web.servlet.view.RedirectView;
3635

@@ -72,20 +71,18 @@ void init() throws IOException {
7271
.cachePublic();
7372
}
7473

75-
@GetMapping("/**")
76-
public Object process(HttpServletRequest request, WebRequest webRequest) throws IOException {
77-
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
78-
74+
@GetMapping("/{*path}")
75+
public Object process(@PathVariable String path, WebRequest webRequest) throws IOException {
7976
File file = new File(baseDirPath, path);
8077

81-
if (!file.exists()) {
82-
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
83-
}
84-
8578
if (!file.getCanonicalPath().startsWith(baseDirPath)) {
8679
return ResponseEntity.badRequest().build();
8780
}
8881

82+
if (!file.exists()) {
83+
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
84+
}
85+
8986
if (file.isFile()) {
9087
return fileResponse(webRequest, file);
9188
}

src/main/resources/templates/directory-index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ <h1 th:text="|Index of ${path}|">Index of /path</h1>
5353
<td>
5454
<a href="../">../</a>
5555
</td>
56-
<td>-</td>
57-
<td>-</td>
56+
<td></td>
57+
<td></td>
5858
<td></td>
5959
</tr>
6060
<tr th:each="entry : ${entries}">

0 commit comments

Comments
 (0)