|
1 | 1 | package stirling.software.SPDF.controller.api.misc; |
2 | 2 |
|
3 | | -import io.github.pixee.security.Filenames; |
4 | | -import io.swagger.v3.oas.annotations.Operation; |
5 | | -import io.swagger.v3.oas.annotations.tags.Tag; |
6 | | -import lombok.RequiredArgsConstructor; |
| 3 | +import java.nio.charset.StandardCharsets; |
| 4 | +import java.util.Map; |
| 5 | + |
7 | 6 | import org.apache.pdfbox.pdmodel.PDDocument; |
8 | 7 | import org.apache.pdfbox.pdmodel.common.PDNameTreeNode; |
9 | 8 | import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; |
|
14 | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
15 | 14 | import org.springframework.web.bind.annotation.RestController; |
16 | 15 | import org.springframework.web.multipart.MultipartFile; |
| 16 | + |
| 17 | +import io.github.pixee.security.Filenames; |
| 18 | +import io.swagger.v3.oas.annotations.Operation; |
| 19 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 20 | + |
| 21 | +import lombok.RequiredArgsConstructor; |
| 22 | + |
17 | 23 | import stirling.software.common.model.api.PDFFile; |
18 | 24 | import stirling.software.common.service.CustomPDFDocumentFactory; |
19 | 25 | import stirling.software.common.util.WebResponseUtils; |
20 | 26 |
|
21 | | -import java.nio.charset.StandardCharsets; |
22 | | -import java.util.Map; |
23 | | - |
24 | 27 | @RestController |
25 | 28 | @RequestMapping("/api/v1/misc") |
26 | 29 | @Tag(name = "Misc", description = "Miscellaneous APIs") |
@@ -55,22 +58,25 @@ public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile file) throws |
55 | 58 |
|
56 | 59 | if (jsCodeStr != null && !jsCodeStr.trim().isEmpty()) { |
57 | 60 | script.append("// File: ") |
58 | | - .append(Filenames.toSimpleFileName(inputFile.getOriginalFilename())) |
59 | | - .append(", Script: ") |
60 | | - .append(name) |
61 | | - .append("\n") |
62 | | - .append(jsCodeStr) |
63 | | - .append("\n"); |
| 61 | + .append( |
| 62 | + Filenames.toSimpleFileName( |
| 63 | + inputFile.getOriginalFilename())) |
| 64 | + .append(", Script: ") |
| 65 | + .append(name) |
| 66 | + .append("\n") |
| 67 | + .append(jsCodeStr) |
| 68 | + .append("\n"); |
64 | 69 | foundScript = true; |
65 | 70 | } |
66 | 71 | } |
67 | 72 | } |
68 | 73 | } |
69 | 74 |
|
70 | 75 | if (!foundScript) { |
71 | | - script = new StringBuilder("PDF '") |
72 | | - .append(Filenames.toSimpleFileName(inputFile.getOriginalFilename())) |
73 | | - .append("' does not contain Javascript"); |
| 76 | + script = |
| 77 | + new StringBuilder("PDF '") |
| 78 | + .append(Filenames.toSimpleFileName(inputFile.getOriginalFilename())) |
| 79 | + .append("' does not contain Javascript"); |
74 | 80 | } |
75 | 81 |
|
76 | 82 | return WebResponseUtils.bytesToWebResponse( |
|
0 commit comments