package com.xuqm.tenant.controller; import com.xuqm.common.model.ApiResponse; import com.xuqm.tenant.entity.FeatureServiceEntity; import com.xuqm.tenant.repository.AppRepository; import com.xuqm.tenant.repository.FeatureServiceRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api/sdk") public class SdkConfigController { private final AppRepository appRepository; private final FeatureServiceRepository featureServiceRepository; @Value("${sdk.im-ws-url:wss://sentry.xuqinmin.com/ws/im}") private String imWsUrl; @Value("${sdk.file-service-url:https://sentry.xuqinmin.com}") private String fileServiceUrl; @Value("${sdk.im-api-url:https://sentry.xuqinmin.com}") private String imApiUrl; public SdkConfigController(AppRepository appRepository, FeatureServiceRepository featureServiceRepository) { this.appRepository = appRepository; this.featureServiceRepository = featureServiceRepository; } /** * GET /api/sdk/config?appId=XXX — public, no auth required. * * Returns SDK configuration URLs and enabled feature flags for the given appId. * Returns 404 if the appId does not exist in the system. */ @GetMapping("/config") public ResponseEntity> getConfig( @RequestParam String appId) { if (!appRepository.existsById(appId)) { return ResponseEntity.status(404) .body(ApiResponse.error(404, "App not found: " + appId)); } List features = featureServiceRepository.findByAppId(appId); boolean imEnabled = features.stream() .anyMatch(f -> f.getServiceType() == FeatureServiceEntity.ServiceType.IM && f.isEnabled()); boolean pushEnabled = features.stream() .anyMatch(f -> f.getServiceType() == FeatureServiceEntity.ServiceType.PUSH && f.isEnabled()); boolean updateEnabled = features.stream() .anyMatch(f -> f.getServiceType() == FeatureServiceEntity.ServiceType.UPDATE && f.isEnabled()); SdkConfigResponse response = new SdkConfigResponse( imWsUrl, fileServiceUrl, imApiUrl, Map.of( "im", imEnabled, "push", pushEnabled, "update", updateEnabled ) ); return ResponseEntity.ok(ApiResponse.success(response)); } public record SdkConfigResponse( String imWsUrl, String fileServiceUrl, String imApiUrl, Map features ) {} }