2024-10-14 22:34:41 +01:00
|
|
|
package stirling.software.SPDF.controller.api;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.stereotype.Controller;
|
2024-12-24 09:52:53 +00:00
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
2024-10-14 22:34:41 +01:00
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Hidden;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
2025-01-06 12:41:30 +00:00
|
|
|
import stirling.software.SPDF.config.InstallationPathConfig;
|
2024-10-14 22:34:41 +01:00
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
|
|
|
import stirling.software.SPDF.utils.GeneralUtils;
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
@Tag(name = "Settings", description = "Settings APIs")
|
|
|
|
@RequestMapping("/api/v1/settings")
|
|
|
|
@Hidden
|
|
|
|
public class SettingsController {
|
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
|
|
|
public SettingsController(ApplicationProperties applicationProperties) {
|
|
|
|
this.applicationProperties = applicationProperties;
|
|
|
|
}
|
2024-10-14 22:34:41 +01:00
|
|
|
|
|
|
|
@PostMapping("/update-enable-analytics")
|
|
|
|
@Hidden
|
|
|
|
public ResponseEntity<String> updateApiKey(@RequestBody Boolean enabled) throws IOException {
|
|
|
|
if (!"undefined".equals(applicationProperties.getSystem().getEnableAnalytics())) {
|
|
|
|
return ResponseEntity.status(HttpStatus.ALREADY_REPORTED)
|
|
|
|
.body(
|
2025-01-06 12:41:30 +00:00
|
|
|
"Setting has already been set, To adjust please edit "
|
|
|
|
+ InstallationPathConfig.getSettingsPath());
|
2024-10-14 22:34:41 +01:00
|
|
|
}
|
|
|
|
GeneralUtils.saveKeyToConfig("system.enableAnalytics", String.valueOf(enabled), false);
|
|
|
|
applicationProperties.getSystem().setEnableAnalytics(String.valueOf(enabled));
|
|
|
|
return ResponseEntity.ok("Updated");
|
|
|
|
}
|
|
|
|
}
|