Refactor particle management: remove secret key from file operations, add ParticleManagerComponent, update frame naming conventions, and enhance style and functionality.

This commit is contained in:
2026-01-04 05:22:04 +01:00
parent 63aa7fd550
commit 8a0843128c
12 changed files with 164 additions and 35 deletions
@@ -57,6 +57,8 @@ public class SecurityConfig {
.requestMatchers("/api/head_mod/**").hasAuthority(PermissionClaimDto.HEAD_MOD.getValue())
.requestMatchers("/api/particles/**").hasAuthority(PermissionClaimDto.HEAD_MOD.getValue())
.requestMatchers("/api/files/save/**").hasAuthority(PermissionClaimDto.HEAD_MOD.getValue())
//TODO allow users access to their own folder
.requestMatchers("/api/files/download/**").hasAuthority(PermissionClaimDto.HEAD_MOD.getValue())
.requestMatchers("/api/history/admin/**").hasAuthority(PermissionClaimDto.HEAD_MOD.getValue())
.requestMatchers("/api/login/userLogin/**").permitAll()
.anyRequest().permitAll()
@@ -34,24 +34,17 @@ public class ParticleController implements ParticlesApi {
private String notificationServerUrl;
@Override
public ResponseEntity<Resource> downloadFile(String authorization, String filename) throws Exception {
if (authorization == null || !authorization.equals(loginSecret)) {
return ResponseEntity.status(401).build();
}
public ResponseEntity<Resource> downloadFile(String filename) {
File file = new File(particlesFilePath);
if (!file.exists() || !file.isDirectory()) {
log.error("Particles file path {} is not a directory, not downloading particles file", particlesFilePath);
return ResponseEntity.status(404).build();
}
File targetFile = new File(file, filename);
return getFileForDownload(targetFile, filename);
return getFileForDownload(file, filename);
}
@Override
public ResponseEntity<Resource> downloadFileForUser(String authorization, String uuid, String filename) throws Exception {
if (authorization == null || !authorization.equals(loginSecret)) {
return ResponseEntity.status(401).build();
}
public ResponseEntity<Resource> downloadFileForUser(String uuid, String filename) {
File file = new File(particlesFilePath);
if (!file.exists() || !file.isDirectory()) {
log.error("Particles file path {} is not a directory, not downloading particles user file", particlesFilePath);
@@ -67,6 +60,7 @@ public class ParticleController implements ParticlesApi {
}
private ResponseEntity<Resource> getFileForDownload(File file, String filename) {
filename += ".json";
File targetFile = new File(file, filename);
if (!targetFile.exists()) {
log.warn("Particles file {} does not exist", targetFile.getAbsolutePath());
@@ -95,7 +89,7 @@ public class ParticleController implements ParticlesApi {
}
@Override
public ResponseEntity<Void> saveFile(String filename, MultipartFile content) throws Exception {
public ResponseEntity<Void> saveFile(String filename, MultipartFile content) {
File file = new File(particlesFilePath);
if (!file.exists() || !file.isDirectory()) {
log.error("Particles file path {} is not a directory, not saving particles file", particlesFilePath);
@@ -107,7 +101,7 @@ public class ParticleController implements ParticlesApi {
}
@Override
public ResponseEntity<Void> saveFileForUser(String uuid, String filename, MultipartFile content) throws Exception {
public ResponseEntity<Void> saveFileForUser(String uuid, String filename, MultipartFile content) {
File file = new File(particlesFilePath);
if (!file.exists() || !file.isDirectory()) {
log.error("Particles file path {} is not a directory, not saving particles user file", particlesFilePath);
@@ -127,7 +121,7 @@ public class ParticleController implements ParticlesApi {
}
private void notifyServerOfFileUpload(String filename) {
String notificationUrl = String.format("%s/notify/%s.json", notificationServerUrl, filename);
String notificationUrl = String.format("http://%s/notify/%s.json", notificationServerUrl, filename);
sendNotification(notificationUrl, String.format("file upload: %s", filename));
}
@@ -154,6 +148,7 @@ public class ParticleController implements ParticlesApi {
private ResponseEntity<Void> writeContentToFile(File dir, String filename, MultipartFile content) {
filename += ".json";
File targetFile = new File(dir, filename);
if (!Files.isWritable(targetFile.toPath())) {
log.error("Particles file {} is not writable", targetFile.getAbsolutePath());