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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-04-25 15:35:12 +02:00
|
|
|
import lombok.RequiredArgsConstructor;
|
2024-12-17 10:26:18 +01:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-02-23 13:36:21 +00:00
|
|
|
|
2024-01-03 23:01:33 +00:00
|
|
|
import stirling.software.SPDF.model.Dependency;
|
2025-04-28 17:36:27 +01:00
|
|
|
import stirling.software.common.configuration.ApplicationProperties;
|
2024-01-03 23:01:33 +00:00
|
|
|
|
2023-06-25 09:16:32 +01:00
|
|
|
@Controller
|
2024-12-17 10:26:18 +01:00
|
|
|
@Slf4j
|
2025-04-25 15:35:12 +02:00
|
|
|
@RequiredArgsConstructor
|
2023-06-25 09:16:32 +01:00
|
|
|
public class HomeWebController {
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
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
|
|
|
|
2024-01-03 23:01:33 +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);
|
2024-01-03 23:01:33 +00:00
|
|
|
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>>>() {});
|
2024-01-03 23:01:33 +00:00
|
|
|
model.addAttribute("dependencies", data.get("dependencies"));
|
|
|
|
} catch (IOException e) {
|
2024-12-17 10:26:18 +01:00
|
|
|
log.error("exception", e);
|
2024-01-03 23:01:33 +00:00
|
|
|
}
|
|
|
|
return "licenses";
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-11-26 20:50:35 +00:00
|
|
|
@GetMapping("/releases")
|
|
|
|
public String getReleaseNotes(Model model) {
|
|
|
|
return "releases";
|
|
|
|
}
|
|
|
|
|
2023-06-25 09:16:32 +01:00
|
|
|
@GetMapping("/")
|
|
|
|
public String home(Model model) {
|
|
|
|
model.addAttribute("currentPage", "home");
|
Add SHOW_SURVEY Environment variable to Docker (#3378)
In the previous implementation, the survey was displayed on the main
screen when the homepage was opened for the 5th, 10th, 15th, 22nd, 30th,
50th, 75th, 100th, 150th, or 200th time, as long as the "Do not show
again" option hadn't been selected.
With this new feature, if the SHOW_SURVEY environment variable is set to
true or not set at all in the Docker configuration, the survey will
continue to be shown as before.
<img width="1679" alt="Screenshot 2025-04-18 at 08 17 37"
src="https://github.com/user-attachments/assets/696b9dc2-9502-4d66-9991-d2b81b52cd02"
/>
However, if the SHOW_SURVEY parameter is explicitly set to false, the
survey will no longer be displayed.
<img width="1707" alt="Screenshot 2025-04-18 at 08 18 39"
src="https://github.com/user-attachments/assets/b57c568a-b5e7-4927-bccf-f9a398bea702"
/>
Closes #1573
---
## Checklist
### General
- [X] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [X] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [X] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [X] I have performed a self-review of my own code
- [X] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [X] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [X] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-04-20 13:49:34 +03:00
|
|
|
String showSurvey = System.getenv("SHOW_SURVEY");
|
|
|
|
boolean showSurveyValue = showSurvey == null || "true".equalsIgnoreCase(showSurvey);
|
|
|
|
model.addAttribute("showSurveyFromDocker", showSurveyValue);
|
2023-06-25 09:16:32 +01:00
|
|
|
return "home";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/home")
|
|
|
|
public String root(Model model) {
|
|
|
|
return "redirect:/";
|
|
|
|
}
|
2023-08-26 22:33:23 +01:00
|
|
|
|
2025-01-30 18:55:33 +00:00
|
|
|
@GetMapping("/home-legacy")
|
|
|
|
public String homeLegacy(Model model) {
|
|
|
|
model.addAttribute("currentPage", "home-legacy");
|
|
|
|
return "home-legacy";
|
|
|
|
}
|
|
|
|
|
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: /";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|