Compare commits

...

3 Commits

Author SHA1 Message Date
hy001
f7a08cdf09 修改上传限制 2026-05-15 11:19:13 +08:00
hy001
bbc4a267be fix: kick realtime sessions on admin account ban 2026-05-14 17:07:58 +08:00
hy001
04097e530e fix(other): allow Hong Kong login region 2026-05-14 15:57:27 +08:00
10 changed files with 65 additions and 41 deletions

View File

@ -2,12 +2,13 @@ package com.red.circle.console.adapter.app.party3rd;//package com.sugartime.app.
import com.red.circle.external.inner.endpoint.oss.OssServiceClient; import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.asserts.ResponseAssert;
import java.io.InputStream;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -57,23 +58,30 @@ public class AliYunRestController {
fileHeaders.setContentType(MediaType.parseMediaType(file.getContentType())); fileHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
} }
ByteArrayResource resource = new ByteArrayResource(file.getBytes()) { String uploadUrl = externalBaseUrl.replaceAll("/+$", "")
+ "/oss/upload/general?dir=" + encode(dir)
+ "&filename=" + encode(filename);
ResponseEntity<Map> response;
try (InputStream inputStream = file.getInputStream()) {
InputStreamResource resource = new InputStreamResource(inputStream) {
@Override @Override
public String getFilename() { public String getFilename() {
return Objects.toString(file.getOriginalFilename(), "upload.bin"); return Objects.toString(file.getOriginalFilename(), "upload.bin");
} }
@Override
public long contentLength() {
return file.getSize();
}
}; };
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new HttpEntity<>(resource, fileHeaders)); body.add("file", new HttpEntity<>(resource, fileHeaders));
response = new RestTemplate().postForEntity(
String uploadUrl = externalBaseUrl.replaceAll("/+$", "")
+ "/oss/upload/general?dir=" + encode(dir)
+ "&filename=" + encode(filename);
ResponseEntity<Map> response = new RestTemplate().postForEntity(
uploadUrl, uploadUrl,
new HttpEntity<>(body, requestHeaders), new HttpEntity<>(body, requestHeaders),
Map.class); Map.class);
}
Map<?, ?> responseBody = response.getBody(); Map<?, ?> responseBody = response.getBody();
if (responseBody == null || !Boolean.TRUE.equals(responseBody.get("status"))) { if (responseBody == null || !Boolean.TRUE.equals(responseBody.get("status"))) {
String errorMsg = responseBody == null ? "upload failed" String errorMsg = responseBody == null ? "upload failed"

View File

@ -69,6 +69,7 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
}*/ }*/
public void processUpdateAccountStatus(ApprovalAccountCmd param) { public void processUpdateAccountStatus(ApprovalAccountCmd param) {
boolean realtimeKicked = false;
// 警告 // 警告
if (ConsoleAccountStatusEnum.WARNING.eq(param.getAccountStatusEnum())) { if (ConsoleAccountStatusEnum.WARNING.eq(param.getAccountStatusEnum())) {
@ -112,8 +113,8 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
redisService redisService
.delete(SecurityConstant.getAccessTokenCacheKeyMd5(param.getBeApprovalUserId())); .delete(SecurityConstant.getAccessTokenCacheKeyMd5(param.getBeApprovalUserId()));
imAccountClient.kick(param.getBeApprovalUserId()); kickUserAndRemoveAuthToken(param.getBeApprovalUserId());
authClient.removeToken(param.getBeApprovalUserId()); realtimeKicked = true;
} }
// 封禁+设备 // 封禁+设备
else if (ConsoleAccountStatusEnum.ARCHIVE_DEVICE.eq(param.getAccountStatusEnum())) { else if (ConsoleAccountStatusEnum.ARCHIVE_DEVICE.eq(param.getAccountStatusEnum())) {
@ -137,8 +138,7 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
redisService redisService
.delete(SecurityConstant.getAccessTokenCacheKeyMd5(relationUser.getUserId())); .delete(SecurityConstant.getAccessTokenCacheKeyMd5(relationUser.getUserId()));
imAccountClient.kick(relationUser.getUserId()); kickUserAndRemoveAuthToken(relationUser.getUserId());
authClient.removeToken(relationUser.getUserId());
ResponseAssert.requiredSuccess(newsletterClient.send( ResponseAssert.requiredSuccess(newsletterClient.send(
new NewsletterResultCmd() new NewsletterResultCmd()
.setUserIds(List.of(relationUser.getUserId())) .setUserIds(List.of(relationUser.getUserId()))
@ -215,7 +215,9 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
return; return;
} }
removeTrtcRoom(param); if (!realtimeKicked) {
removeTrtcRoom(param.getBeApprovalUserId());
}
addLog(param, param.getBeApprovalUserId()); addLog(param, param.getBeApprovalUserId());
@ -223,9 +225,15 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
} }
private void removeTrtcRoom(ApprovalAccountCmd param) { private void kickUserAndRemoveAuthToken(Long userId) {
imAccountClient.kick(userId);
authClient.removeToken(userId);
removeTrtcRoom(userId);
}
private void removeTrtcRoom(Long userId) {
String sessionId = ResponseAssert.requiredSuccess( String sessionId = ResponseAssert.requiredSuccess(
userOnlineClient.getSessionId(param.getBeApprovalUserId())); userOnlineClient.getSessionId(userId));
if (Objects.nonNull(sessionId)) { if (Objects.nonNull(sessionId)) {
RoomProfileDTO roomProfile = ResponseAssert.requiredSuccess( RoomProfileDTO roomProfile = ResponseAssert.requiredSuccess(
roomManagerClient.getProfileById(Long.valueOf(sessionId))); roomManagerClient.getProfileById(Long.valueOf(sessionId)));
@ -233,7 +241,7 @@ public class UserDataViolationServiceImpl implements UserDataViolationService {
trtcClient.removeUser( trtcClient.removeUser(
new TrtcRemoveUserCmd() new TrtcRemoveUserCmd()
.setRoomId(Long.parseLong(roomProfile.getRoomAccount())) .setRoomId(Long.parseLong(roomProfile.getRoomAccount()))
.setUserIds(List.of(param.getBeApprovalUserId())) .setUserIds(List.of(userId))
); );
} }
} }

View File

@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class UndertowUploadLimitConfiguration { public class UndertowUploadLimitConfiguration {
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024; private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
@Bean @Bean
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() { public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {

View File

@ -4,7 +4,7 @@ server:
servlet: servlet:
context-path: /console context-path: /console
undertow: undertow:
max-http-post-size: 20MB max-http-post-size: 500MB
no-request-timeout: 60000 no-request-timeout: 60000
spring: spring:
@ -20,8 +20,8 @@ spring:
prod: prod,web-framework,openfeign,mybatis-plus prod: prod,web-framework,openfeign,mybatis-plus
servlet: servlet:
multipart: multipart:
max-file-size: 20MB max-file-size: 500MB
max-request-size: 20MB max-request-size: 500MB
enabled: true enabled: true
--- ---
spring: spring:

View File

@ -31,7 +31,7 @@ import java.util.UUID;
public class OssRestController { public class OssRestController {
private static final Logger log = LoggerFactory.getLogger(OssRestController.class); private static final Logger log = LoggerFactory.getLogger(OssRestController.class);
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024; private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
private final AliYunStsService aliYunStsService; private final AliYunStsService aliYunStsService;
private final OssService ossService; private final OssService ossService;
@ -78,7 +78,7 @@ public class OssRestController {
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL); return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
} }
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) { if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_20M); return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_500M);
} }
String name = file.getOriginalFilename().toLowerCase(); String name = file.getOriginalFilename().toLowerCase();
if(!FileUtils.fileContentType(name)) { if(!FileUtils.fileContentType(name)) {
@ -123,7 +123,7 @@ public class OssRestController {
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL); return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
} }
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) { if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_20M); return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_500M);
} }
String storageKey = buildStorageKey(dir, filename, file.getOriginalFilename()); String storageKey = buildStorageKey(dir, filename, file.getOriginalFilename());
if (tencentCosStorageService.isEnabled()) { if (tencentCosStorageService.isEnabled()) {

View File

@ -5,7 +5,7 @@ import com.red.circle.framework.dto.IResponseErrorCode;
public enum OssErrorCode implements IResponseErrorCode { public enum OssErrorCode implements IResponseErrorCode {
FILE_IS_NULL(20001, "file is null"), FILE_IS_NULL(20001, "file is null"),
FILE_TYPE_NOT_SUPPORTED(20003, "File type not supported"), FILE_TYPE_NOT_SUPPORTED(20003, "File type not supported"),
FILE_SIZE_GREATER_THAN_20M(20003, "File size greater than 20M"), FILE_SIZE_GREATER_THAN_500M(20003, "File size greater than 500M"),
NETWORK_ANOMALY(20004, "network anomaly"); NETWORK_ANOMALY(20004, "network anomaly");
private final int code; private final int code;

View File

@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class UndertowUploadLimitConfiguration { public class UndertowUploadLimitConfiguration {
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024; private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
@Bean @Bean
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() { public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {

View File

@ -2,7 +2,7 @@ server:
port: 3000 port: 3000
shutdown: graceful shutdown: graceful
undertow: undertow:
max-http-post-size: 20MB max-http-post-size: 500MB
no-request-timeout: 60000 no-request-timeout: 60000
spring: spring:
@ -12,8 +12,8 @@ spring:
allow-bean-definition-overriding: true allow-bean-definition-overriding: true
servlet: servlet:
multipart: multipart:
max-file-size: 20MB max-file-size: 500MB
max-request-size: 20MB max-request-size: 500MB
enabled: true enabled: true
profiles: profiles:
active: @profiles.active@ active: @profiles.active@

View File

@ -32,10 +32,10 @@ public class IpCountryUtils {
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan" "香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan"
); );
private static final List<String> BLOCKED_COUNTRY_CODES = List.of( private static final List<String> BLOCKED_COUNTRY_CODES = List.of(
"HK", "MO", "SG", "TW" "MO", "SG", "TW"
); );
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of( private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan", "新加坡", "Singapore" "澳门", "澳門", "台湾", "台灣", "Macau", "Macao", "Taiwan", "新加坡", "Singapore"
); );
private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of( private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of(
new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"), new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"),

View File

@ -69,11 +69,19 @@ public class IpCountryUtilsTest {
} }
@Test @Test
public void blockHongKongRegion() { public void allowHongKongRegion() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "香港", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "香港", "test");
assertFalse(IpCountryUtils.isMainlandChina(data)); assertFalse(IpCountryUtils.isMainlandChina(data));
assertTrue(IpCountryUtils.isBlockedIpRegion(data)); assertFalse(IpCountryUtils.isBlockedIpRegion(data));
}
@Test
public void allowHongKongCountryCode() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("HK", "Hong Kong", "", "test");
assertFalse(IpCountryUtils.isMainlandChina(data));
assertFalse(IpCountryUtils.isBlockedIpRegion(data));
} }
@Test @Test