mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 15:35:03 +00:00
Api fix
This commit is contained in:
parent
5d611a2fa3
commit
4f6286845d
@ -27,17 +27,14 @@ public class MetricsFilter extends OncePerRequestFilter {
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
String uri = request.getRequestURI();
|
||||
|
||||
//System.out.println("uri="+uri + ", method=" + request.getMethod() );
|
||||
// Ignore static resources
|
||||
if (!(uri.startsWith("/js") || uri.startsWith("api-docs") || uri.endsWith("robots.txt") || uri.startsWith("/images") || uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".svg")|| uri.endsWith(".js") || uri.contains("swagger") || uri.startsWith("/api"))) {
|
||||
if (!(uri.startsWith("/api/v1/info") || uri.startsWith("/js") || uri.startsWith("api-docs") || uri.endsWith("robots.txt") || uri.startsWith("/images") || uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".svg")|| uri.endsWith(".js") || uri.contains("swagger"))) {
|
||||
Counter counter = Counter.builder("http.requests")
|
||||
.tag("uri", uri)
|
||||
.tag("method", request.getMethod())
|
||||
.register(meterRegistry);
|
||||
|
||||
counter.increment();
|
||||
//System.out.println("Counted");
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
|
@ -1,27 +1,42 @@
|
||||
package stirling.software.SPDF.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import stirling.software.SPDF.model.ApplicationProperties;
|
||||
|
||||
@Configuration
|
||||
public class OpenApiConfig {
|
||||
|
||||
@Autowired
|
||||
ApplicationProperties applicationProperties;
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
String version = getClass().getPackage().getImplementationVersion();
|
||||
if (version == null) {
|
||||
|
||||
version = "1.0.0"; // default version if all else fails
|
||||
|
||||
}
|
||||
String version = getClass().getPackage().getImplementationVersion();
|
||||
if (version == null) {
|
||||
version = "1.0.0"; // default version if all else fails
|
||||
}
|
||||
|
||||
SecurityScheme apiKeyScheme = new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)
|
||||
.name("X-API-KEY");
|
||||
if (!applicationProperties.getSecurity().getEnableLogin()) {
|
||||
return new OpenAPI().components(new Components())
|
||||
.info(new Info().title("Stirling PDF API").version(version).description(
|
||||
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
|
||||
} else {
|
||||
return new OpenAPI().components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
|
||||
.info(new Info().title("Stirling PDF API").version(version).description(
|
||||
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."))
|
||||
.addSecurityItem(new SecurityRequirement().addList("apiKey"));
|
||||
}
|
||||
|
||||
return new OpenAPI().components(new Components()).info(
|
||||
new Info().title("Stirling PDF API").version(version).description("API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class GeneralWebController {
|
||||
@GetMapping("/add-elements")
|
||||
@Hidden
|
||||
public String addElements(Model model) {
|
||||
model.addAttribute("currentPage", "sign");
|
||||
model.addAttribute("currentPage", "add-elements");
|
||||
model.addAttribute("fonts", getFontNames());
|
||||
return "add-elements";
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ import stirling.software.SPDF.config.StartupApplicationListener;
|
||||
import stirling.software.SPDF.model.ApplicationProperties;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1")
|
||||
@Tag(name = "API", description = "Info APIs")
|
||||
@RequestMapping("/api/v1/info")
|
||||
@Tag(name = "Info", description = "Info APIs")
|
||||
public class MetricsController {
|
||||
|
||||
|
||||
@ -181,6 +181,7 @@ public class MetricsController {
|
||||
for (Meter meter : meterRegistry.getMeters()) {
|
||||
if (meter.getId().getName().equals("http.requests")) {
|
||||
String method = meter.getId().getTag("method");
|
||||
System.out.println("method=" + method + ", endpont=" + endpoint.get());
|
||||
if (method != null && method.equals("POST")) {
|
||||
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
||||
if (!endpoint.get().startsWith("/")) {
|
||||
@ -217,10 +218,15 @@ public class MetricsController {
|
||||
Map<String, Double> counts = new HashMap<>();
|
||||
|
||||
for (Meter meter : meterRegistry.getMeters()) {
|
||||
|
||||
System.out.println("meter.getId().getName()=" + meter.getId().getName());
|
||||
if (meter.getId().getName().equals("http.requests")) {
|
||||
String method = meter.getId().getTag("method");
|
||||
System.out.println("method=" + method );
|
||||
if (method != null && method.equals("POST")) {
|
||||
String uri = meter.getId().getTag("uri");
|
||||
String uri = meter.getId().getTag("uri");
|
||||
System.out.println("method=" + method + ", endpont=" + meter.getId());
|
||||
|
||||
if (uri != null) {
|
||||
double currentCount = counts.getOrDefault(uri, 0.0);
|
||||
if (meter instanceof Counter) {
|
||||
|
@ -182,7 +182,7 @@
|
||||
<input type="text" class="form-control" id="sigText" name="sigText">
|
||||
<label th:text="#{font}"></label>
|
||||
<select class="form-control" name="font" id="font-select">
|
||||
<option th:each="font : ${fonts}" th:value="${font}" th:text="${font}" th:class="${font.toLowerCase()+'-font'}"></option>
|
||||
<option th:each="font : ${fonts}" th:value="${font}" th:text="${font}" th:class="${font + '-font'}"></option>
|
||||
|
||||
</select>
|
||||
<div class="margin-auto-parent">
|
||||
|
Loading…
x
Reference in New Issue
Block a user