Added upload speedtest
- Updated CORS to apply for all API endpoints - Added database docker compose
This commit is contained in:
@ -14,7 +14,7 @@ public class CorsConfig implements WebMvcConfigurer {
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
System.out.println("CORS CONFIGURATION ENABLED | DEVELOPMENT PROFILE");
|
||||
System.out.println("IF YOU SEE THIS MESSAGE IN PRODUCTION, PLEASE DISABLE DEVELOPEMENT MODE IN APPLICATION.PROPERTIES");
|
||||
registry.addMapping("/api/v1/speed-test")
|
||||
registry.addMapping("/api/v1/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*");
|
||||
|
@ -1,12 +1,16 @@
|
||||
package de.w665.sharepulse.rest.mappings;
|
||||
|
||||
import de.w665.sharepulse.rest.ApiRestController;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ -30,4 +34,23 @@ public class SpeedTest extends ApiRestController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/upload-speed-test")
|
||||
public void uploadSpeedTest(HttpServletRequest request, HttpServletResponse response) {
|
||||
final int maxBytes = 1024 * 1024; // Limit to 1MB
|
||||
byte[] buffer = new byte[1024]; // Buffer to read data
|
||||
int bytesRead;
|
||||
int totalBytesRead = 0;
|
||||
|
||||
try (InputStream inputStream = request.getInputStream()) {
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1 && totalBytesRead < maxBytes) {
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
} catch (IOException e) {
|
||||
log.error("Upload speed test failed.", e);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user