Added JSON response to Upload endpoint
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package de.w665.sharepulse.rest.mappings;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.w665.sharepulse.model.FileUpload;
|
||||
import de.w665.sharepulse.rest.ApiRestController;
|
||||
import de.w665.sharepulse.service.FileService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -38,8 +40,16 @@ public class Upload extends ApiRestController {
|
||||
return new ResponseEntity<>("Please select a file to upload.", HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
String fileId = fileService.processUploadedFile(file, request.getRemoteAddr(), password, singleDownload, fileDescription);
|
||||
FileUpload fileUpload = fileService.processUploadedFile(file, request.getRemoteAddr(), password, singleDownload, fileDescription);
|
||||
log.debug("User uploaded file " + file.getOriginalFilename() + " from IP " + request.getRemoteAddr() + " successfully.");
|
||||
return new ResponseEntity<>("File " + file.getOriginalFilename() + " uploaded successfully! ID(" + fileId + ")", HttpStatus.OK);
|
||||
|
||||
JsonObject response = new JsonObject();
|
||||
response.addProperty("fileId", fileUpload.getFileId());
|
||||
response.addProperty("message", "File " + file.getOriginalFilename() + " uploaded successfully!");
|
||||
response.addProperty("passwordProtected", fileUpload.isPasswordProtected());
|
||||
response.addProperty("singleDownload", fileUpload.isSingleDownload());
|
||||
response.addProperty("uploadDate", fileUpload.getUploadDate().toString());
|
||||
|
||||
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class FileService {
|
||||
}
|
||||
}
|
||||
|
||||
public String processUploadedFile(MultipartFile file, String uploaderIp, String password, boolean singleDownload, String fileDescription) {
|
||||
public FileUpload processUploadedFile(MultipartFile file, String uploaderIp, String password, boolean singleDownload, String fileDescription) {
|
||||
|
||||
String fileId = fileIdService.generateNewUniqueId();
|
||||
|
||||
@ -80,7 +80,7 @@ public class FileService {
|
||||
try {
|
||||
Files.write(path, file.getBytes());
|
||||
log.debug("File " + file.getOriginalFilename() + " written to " + path.getFileName());
|
||||
return fileId;
|
||||
return fileUpload;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user