Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.7 KiB
Java
Raw Normal View History

2023-06-25 09:16:32 +01:00
package stirling.software.SPDF.controller.web;
2024-01-04 23:04:15 +00:00
import java.io.IOException;
2024-01-09 22:39:21 +00:00
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
2024-01-04 23:04:15 +00:00
import java.util.List;
import java.util.Map;
2024-06-02 11:59:43 +01:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2023-08-26 22:33:23 +01:00
import org.springframework.beans.factory.annotation.Autowired;
2024-01-04 23:04:15 +00:00
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
2023-06-25 09:16:32 +01:00
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
2024-01-04 23:04:15 +00:00
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
2023-06-25 09:16:32 +01:00
import io.swagger.v3.oas.annotations.Hidden;
2023-12-30 19:11:27 +00:00
2023-08-26 22:33:23 +01:00
import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.model.Dependency;
2023-06-25 09:16:32 +01:00
@Controller
public class HomeWebController {
2023-12-30 19:11:27 +00:00
2024-06-02 11:59:43 +01:00
private static final Logger logger = LoggerFactory.getLogger(HomeWebController.class);
2023-06-25 09:16:32 +01:00
@GetMapping("/about")
@Hidden
public String gameForm(Model model) {
model.addAttribute("currentPage", "about");
return "about";
}
2024-01-04 23:04:15 +00:00
@GetMapping("/licenses")
@Hidden
public String licensesForm(Model model) {
model.addAttribute("currentPage", "licenses");
Resource resource = new ClassPathResource("static/3rdPartyLicenses.json");
try {
2024-01-09 22:39:21 +00:00
InputStream is = resource.getInputStream();
String json = new String(is.readAllBytes(), StandardCharsets.UTF_8);
ObjectMapper mapper = new ObjectMapper();
2024-01-04 23:04:15 +00:00
Map<String, List<Dependency>> data =
mapper.readValue(json, new TypeReference<Map<String, List<Dependency>>>() {});
model.addAttribute("dependencies", data.get("dependencies"));
} catch (IOException e) {
2024-06-02 11:59:43 +01:00
logger.error("exception", e);
}
return "licenses";
}
2023-12-30 19:11:27 +00:00
2023-06-25 09:16:32 +01:00
@GetMapping("/")
public String home(Model model) {
model.addAttribute("currentPage", "home");
return "home";
}
@GetMapping("/home")
public String root(Model model) {
return "redirect:/";
}
2023-08-26 22:33:23 +01:00
@Autowired ApplicationProperties applicationProperties;
2023-06-25 09:16:32 +01:00
@GetMapping(value = "/robots.txt", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
@Hidden
public String getRobotsTxt() {
2023-08-26 22:33:23 +01:00
Boolean allowGoogle = applicationProperties.getSystem().getGooglevisibility();
if (Boolean.TRUE.equals(allowGoogle)) {
2023-06-25 09:16:32 +01:00
return "User-agent: Googlebot\nAllow: /\n\nUser-agent: *\nAllow: /";
} else {
return "User-agent: Googlebot\nDisallow: /\n\nUser-agent: *\nDisallow: /";
}
}
}