2023-04-29 00:18:10 +02:00
|
|
|
package stirling.software.SPDF.controller.web;
|
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
import java.io.File;
|
2023-07-09 20:36:41 +02:00
|
|
|
import java.io.IOException;
|
2023-07-26 14:00:06 +02:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URL;
|
2023-07-12 01:17:44 +02:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2023-07-26 14:00:06 +02:00
|
|
|
import java.nio.file.FileSystem;
|
|
|
|
import java.nio.file.FileSystems;
|
2023-07-09 20:36:41 +02:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.List;
|
2023-07-12 01:17:44 +02:00
|
|
|
import java.util.Map;
|
2023-07-09 20:36:41 +02:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2023-04-29 00:18:10 +02:00
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
2023-04-29 00:18:10 +02:00
|
|
|
import io.swagger.v3.oas.annotations.Hidden;
|
2023-06-25 10:16:32 +02:00
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2023-04-29 00:18:10 +02:00
|
|
|
@Controller
|
2023-06-25 10:16:32 +02:00
|
|
|
@Tag(name = "General", description = "General APIs")
|
2023-04-29 00:18:10 +02:00
|
|
|
public class GeneralWebController {
|
2023-07-12 01:17:44 +02:00
|
|
|
|
|
|
|
@GetMapping("/pipeline")
|
|
|
|
@Hidden
|
|
|
|
public String pipelineForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "pipeline");
|
|
|
|
|
|
|
|
List<String> pipelineConfigs = new ArrayList<>();
|
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get("./pipeline/defaultWebUIConfigs/"))) {
|
|
|
|
List<Path> jsonFiles = paths
|
|
|
|
.filter(Files::isRegularFile)
|
|
|
|
.filter(p -> p.toString().endsWith(".json"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
for (Path jsonFile : jsonFiles) {
|
|
|
|
String content = Files.readString(jsonFile, StandardCharsets.UTF_8);
|
|
|
|
pipelineConfigs.add(content);
|
|
|
|
}
|
|
|
|
List<Map<String, String>> pipelineConfigsWithNames = new ArrayList<>();
|
|
|
|
for (String config : pipelineConfigs) {
|
|
|
|
Map<String, Object> jsonContent = new ObjectMapper().readValue(config, Map.class);
|
|
|
|
String name = (String) jsonContent.get("name");
|
|
|
|
Map<String, String> configWithName = new HashMap<>();
|
|
|
|
configWithName.put("json", config);
|
|
|
|
configWithName.put("name", name);
|
|
|
|
pipelineConfigsWithNames.add(configWithName);
|
|
|
|
}
|
|
|
|
model.addAttribute("pipelineConfigsWithNames", pipelineConfigsWithNames);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2023-06-13 01:32:15 +02:00
|
|
|
}
|
2023-07-12 01:17:44 +02:00
|
|
|
|
|
|
|
model.addAttribute("pipelineConfigs", pipelineConfigs);
|
|
|
|
|
|
|
|
return "pipeline";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-13 01:32:15 +02:00
|
|
|
|
2023-04-29 00:18:10 +02:00
|
|
|
@GetMapping("/merge-pdfs")
|
|
|
|
@Hidden
|
|
|
|
public String mergePdfForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "merge-pdfs");
|
|
|
|
return "merge-pdfs";
|
|
|
|
}
|
2023-06-25 10:16:32 +02:00
|
|
|
|
2023-04-29 23:26:16 +02:00
|
|
|
|
2023-04-29 00:18:10 +02:00
|
|
|
@GetMapping("/multi-tool")
|
|
|
|
@Hidden
|
|
|
|
public String multiToolForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "multi-tool");
|
|
|
|
return "multi-tool";
|
|
|
|
}
|
2023-06-25 10:16:32 +02:00
|
|
|
|
2023-04-29 00:18:10 +02:00
|
|
|
|
|
|
|
@GetMapping("/remove-pages")
|
|
|
|
@Hidden
|
|
|
|
public String pageDeleter(Model model) {
|
|
|
|
model.addAttribute("currentPage", "remove-pages");
|
|
|
|
return "remove-pages";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/pdf-organizer")
|
|
|
|
@Hidden
|
|
|
|
public String pageOrganizer(Model model) {
|
|
|
|
model.addAttribute("currentPage", "pdf-organizer");
|
|
|
|
return "pdf-organizer";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/rotate-pdf")
|
|
|
|
@Hidden
|
|
|
|
public String rotatePdfForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "rotate-pdf");
|
|
|
|
return "rotate-pdf";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/split-pdfs")
|
|
|
|
@Hidden
|
|
|
|
public String splitPdfForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "split-pdfs");
|
|
|
|
return "split-pdfs";
|
|
|
|
}
|
2023-05-02 23:59:16 +02:00
|
|
|
|
|
|
|
@GetMapping("/sign")
|
|
|
|
@Hidden
|
|
|
|
public String signForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "sign");
|
2023-07-09 20:36:41 +02:00
|
|
|
model.addAttribute("fonts", getFontNames());
|
2023-05-02 23:59:16 +02:00
|
|
|
return "sign";
|
|
|
|
}
|
2023-07-09 20:36:41 +02:00
|
|
|
private List<String> getFontNames() {
|
2023-07-26 14:00:06 +02:00
|
|
|
List<String> fontNames = new ArrayList<>();
|
|
|
|
|
2023-07-09 20:36:41 +02:00
|
|
|
try {
|
2023-07-26 14:00:06 +02:00
|
|
|
// Get the directory URL from classpath
|
|
|
|
URL dirURL = getClass().getClassLoader().getResource("static/fonts");
|
|
|
|
|
|
|
|
if (dirURL != null && dirURL.getProtocol().equals("file")) {
|
|
|
|
// If running from the file system (e.g., IDE)
|
|
|
|
fontNames.addAll(
|
|
|
|
Files.list(Paths.get(dirURL.toURI()))
|
|
|
|
.map(java.nio.file.Path::getFileName)
|
|
|
|
.map(java.nio.file.Path::toString)
|
|
|
|
.filter(name -> name.endsWith(".woff2"))
|
|
|
|
.map(name -> name.substring(0, name.length() - 6)) // Remove .woff2 extension
|
|
|
|
.collect(Collectors.toList())
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// If running from a JAR file
|
|
|
|
// Resources in JAR go through a different URL protocol.
|
|
|
|
// In this case, we'll use a different approach to list them.
|
|
|
|
|
|
|
|
// Create a link to the resource. This assumes resources are at the root of the JAR.
|
|
|
|
URI uri = getClass().getResource("/").toURI();
|
|
|
|
FileSystem fileSystem = FileSystems.newFileSystem(uri, new HashMap<>());
|
|
|
|
Path myPath = fileSystem.getPath("/static/fonts/");
|
|
|
|
Files.walk(myPath, 1)
|
|
|
|
.filter(path -> !Files.isDirectory(path))
|
|
|
|
.map(path -> path.getFileName().toString())
|
2023-07-09 20:36:41 +02:00
|
|
|
.filter(name -> name.endsWith(".woff2"))
|
|
|
|
.map(name -> name.substring(0, name.length() - 6)) // Remove .woff2 extension
|
2023-07-26 14:00:06 +02:00
|
|
|
.forEach(fontNames::add);
|
|
|
|
fileSystem.close();
|
|
|
|
}
|
|
|
|
} catch (IOException | URISyntaxException e) {
|
2023-07-09 20:36:41 +02:00
|
|
|
throw new RuntimeException("Failed to read font directory", e);
|
|
|
|
}
|
2023-07-26 14:00:06 +02:00
|
|
|
|
|
|
|
return fontNames;
|
2023-07-09 20:36:41 +02:00
|
|
|
}
|
2023-07-26 14:00:06 +02:00
|
|
|
|
2023-07-09 20:36:41 +02:00
|
|
|
|
2023-05-08 01:17:20 +02:00
|
|
|
|
2023-07-09 01:05:33 +02:00
|
|
|
@GetMapping("/crop")
|
|
|
|
@Hidden
|
|
|
|
public String cropForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "crop");
|
|
|
|
return "crop";
|
|
|
|
}
|
2023-07-15 12:39:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/auto-split-pdf")
|
|
|
|
@Hidden
|
|
|
|
public String autoSPlitPDFForm(Model model) {
|
|
|
|
model.addAttribute("currentPage", "auto-split-pdf");
|
|
|
|
return "auto-split-pdf";
|
|
|
|
}
|
2023-04-29 00:18:10 +02:00
|
|
|
}
|