This commit is contained in:
@@ -94,4 +94,33 @@ public class HandlerConfig {
|
|||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Map<Integer, RequestHandler> internalHandlers(
|
||||||
|
StatisticComplaintHandler statisticComplaintHandler,
|
||||||
|
StatisticUserFilesHandler statisticUserHandler,
|
||||||
|
StatisticTariffInfoFileHandler statisticTariffInfoFileHandler,
|
||||||
|
StatisticUserDynamicHandler statisticUserDynamicHandler,
|
||||||
|
StatisticProtectedFilesHandler statisticProtectedFilesHandler,
|
||||||
|
StatisticViolationHandler statisticViolationHandler,
|
||||||
|
StatisticSubscriberHandler statisticSubscriberHandler,
|
||||||
|
StatisticTokenHandler statisticTokenHandler,
|
||||||
|
StatisticIncomeHandler statisticIncomeHandler,
|
||||||
|
MonitoringStatisticHandler monitoringStatisticHandler
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Map<Integer, RequestHandler> map = new HashMap<>();
|
||||||
|
map.put(30019, statisticUserHandler);
|
||||||
|
map.put(30020, statisticTariffInfoFileHandler);
|
||||||
|
map.put(30021, statisticUserDynamicHandler);
|
||||||
|
map.put(30022, statisticProtectedFilesHandler);
|
||||||
|
map.put(30023, statisticViolationHandler);
|
||||||
|
map.put(30024, statisticSubscriberHandler);
|
||||||
|
map.put(30025, statisticTokenHandler);
|
||||||
|
map.put(30026, statisticIncomeHandler);
|
||||||
|
map.put(30027, monitoringStatisticHandler);
|
||||||
|
map.put(30029, statisticComplaintHandler);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public class ApiController {
|
|||||||
|
|
||||||
private final Map<Integer, RequestHandler> handlers;
|
private final Map<Integer, RequestHandler> handlers;
|
||||||
|
|
||||||
|
private final Map<Integer, RequestHandler> internalHandlers;
|
||||||
|
|
||||||
private final FileEntityService fileEntityService;
|
private final FileEntityService fileEntityService;
|
||||||
|
|
||||||
private final AuthService authService;
|
private final AuthService authService;
|
||||||
@@ -126,6 +128,35 @@ public class ApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/internal/data")
|
||||||
|
public ResponseEntity<?> handleInternalPostRequest(@RequestBody BaseRequest request) {
|
||||||
|
Integer msgId = request.getMsgId();
|
||||||
|
BaseResponse response;
|
||||||
|
RequestHandler handler = internalHandlers.get(msgId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (handler == null) {
|
||||||
|
response = new BaseResponse(msgId,
|
||||||
|
MessageCode.MSG_ID_NOT_FOUND.getCode(),
|
||||||
|
MessageCode.MSG_ID_NOT_FOUND.getDescription(),
|
||||||
|
new HashMap<>());
|
||||||
|
} else {
|
||||||
|
response = handler.handle(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Handler execution failed for msgId: {}", msgId, e);
|
||||||
|
|
||||||
|
BaseResponse errorResponse = new BaseResponse(msgId,
|
||||||
|
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||||
|
MessageCode.INVALID_JSON_BODY.getDescription(),
|
||||||
|
new HashMap<>());
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(errorResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/v{version}/files/chunk")
|
@PostMapping("/v{version}/files/chunk")
|
||||||
public ResponseEntity<BaseResponse> uploadChunk(
|
public ResponseEntity<BaseResponse> uploadChunk(
|
||||||
@PathVariable("version") int version,
|
@PathVariable("version") int version,
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.soune.nocopy.util;
|
||||||
|
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class InternalApiFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
@Value("${app.internal-api-key}")
|
||||||
|
private String internalApiKey;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
if (request.getRequestURI().startsWith("api/internal/")) {
|
||||||
|
String providedKey = request.getHeader("X-Internal-Key");
|
||||||
|
|
||||||
|
if (!internalApiKey.equals(providedKey)) {
|
||||||
|
response.sendError(403, "Access Denied: Internal API only");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -135,6 +135,7 @@ yookassa:
|
|||||||
|
|
||||||
|
|
||||||
app:
|
app:
|
||||||
|
internal-api-key: "tljzkXiEYF1klSHuG2hPZKjx6EsBX8RQP6UrzMdQanSKbRYuHuOBwrXejZkn7V4FICvIahoDmYD2hjNBPw61NFbGIt4scOzwZpyCiXEa1YKLAeJSPso4S43LIZlKjO4S"
|
||||||
email:
|
email:
|
||||||
verification:
|
verification:
|
||||||
standart-subject: NO COPY - Подтверждение email адреса
|
standart-subject: NO COPY - Подтверждение email адреса
|
||||||
|
|||||||
Reference in New Issue
Block a user