mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 23:45:02 +00:00

# Description This pull request includes several changes aimed at improving the code structure and removing redundant code. The most significant changes involve reordering methods, removing unnecessary annotations, and refactoring constructors to use dependency injection. Autowired now comes via constructor (which also doesn't need autowired annotation as its done by default for configuration) ## Checklist - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [ ] My changes generate no new warnings - [ ] 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)
50 lines
1.8 KiB
Java
50 lines
1.8 KiB
Java
package stirling.software.SPDF.controller.web;
|
|
|
|
import java.io.IOException;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface;
|
|
import stirling.software.SPDF.service.SignatureService;
|
|
|
|
@Controller
|
|
@RequestMapping("/api/v1/general")
|
|
public class SignatureController {
|
|
|
|
private final SignatureService signatureService;
|
|
|
|
private final UserServiceInterface userService;
|
|
|
|
public SignatureController(
|
|
SignatureService signatureService,
|
|
@Autowired(required = false) UserServiceInterface userService) {
|
|
this.signatureService = signatureService;
|
|
this.userService = userService;
|
|
}
|
|
|
|
@GetMapping("/sign/{fileName}")
|
|
public ResponseEntity<byte[]> getSignature(@PathVariable(name = "fileName") String fileName)
|
|
throws IOException {
|
|
String username = "NON_SECURITY_USER";
|
|
if (userService != null) {
|
|
username = userService.getCurrentUsername();
|
|
}
|
|
// Verify access permission
|
|
if (!signatureService.hasAccessToFile(username, fileName)) {
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
}
|
|
byte[] imageBytes = signatureService.getSignatureBytes(username, fileName);
|
|
return ResponseEntity.ok()
|
|
.contentType( // Adjust based on file type
|
|
MediaType.IMAGE_JPEG)
|
|
.body(imageBytes);
|
|
}
|
|
}
|