2026-04-25 16:41:10 +08:00
|
|
|
package com.xuqm.tenant.controller;
|
|
|
|
|
|
|
|
|
|
import com.xuqm.common.model.ApiResponse;
|
2026-04-27 23:41:58 +08:00
|
|
|
import com.xuqm.tenant.entity.AppEntity;
|
2026-04-25 16:41:10 +08:00
|
|
|
import com.xuqm.tenant.entity.FeatureServiceEntity;
|
|
|
|
|
import com.xuqm.tenant.repository.FeatureServiceRepository;
|
2026-04-27 23:41:58 +08:00
|
|
|
import com.xuqm.tenant.service.SdkAppProvisioningService;
|
2026-04-25 16:41:10 +08:00
|
|
|
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 FeatureServiceRepository featureServiceRepository;
|
2026-04-27 23:41:58 +08:00
|
|
|
private final SdkAppProvisioningService sdkAppProvisioningService;
|
2026-04-25 16:41:10 +08:00
|
|
|
|
2026-04-27 19:23:11 +08:00
|
|
|
@Value("${sdk.im-ws-url:wss://im.dev.xuqinmin.com/ws/im}")
|
2026-04-25 16:41:10 +08:00
|
|
|
private String imWsUrl;
|
|
|
|
|
|
2026-04-27 19:23:11 +08:00
|
|
|
@Value("${sdk.file-service-url:https://file.dev.xuqinmin.com}")
|
2026-04-25 16:41:10 +08:00
|
|
|
private String fileServiceUrl;
|
|
|
|
|
|
2026-04-27 19:23:11 +08:00
|
|
|
@Value("${sdk.im-api-url:https://im.dev.xuqinmin.com}")
|
2026-04-25 16:41:10 +08:00
|
|
|
private String imApiUrl;
|
|
|
|
|
|
2026-04-27 23:41:58 +08:00
|
|
|
public SdkConfigController(FeatureServiceRepository featureServiceRepository,
|
|
|
|
|
SdkAppProvisioningService sdkAppProvisioningService) {
|
2026-04-25 16:41:10 +08:00
|
|
|
this.featureServiceRepository = featureServiceRepository;
|
2026-04-27 23:41:58 +08:00
|
|
|
this.sdkAppProvisioningService = sdkAppProvisioningService;
|
2026-04-25 16:41:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GET /api/sdk/config?appId=XXX — public, no auth required.
|
|
|
|
|
*
|
2026-04-27 23:41:58 +08:00
|
|
|
* Returns SDK configuration URLs and enabled feature flags for the given appId/appKey.
|
|
|
|
|
* The demo app (`ak_demo_chat`) is auto-provisioned if it does not exist.
|
2026-04-25 16:41:10 +08:00
|
|
|
*/
|
|
|
|
|
@GetMapping("/config")
|
|
|
|
|
public ResponseEntity<ApiResponse<SdkConfigResponse>> getConfig(
|
|
|
|
|
@RequestParam String appId) {
|
|
|
|
|
|
2026-04-27 23:41:58 +08:00
|
|
|
AppEntity app = sdkAppProvisioningService.resolveApp(appId);
|
|
|
|
|
List<FeatureServiceEntity> features = featureServiceRepository.findByAppId(app.getAppKey());
|
2026-04-25 16:41:10 +08:00
|
|
|
|
|
|
|
|
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<String, Boolean> features
|
|
|
|
|
) {}
|
|
|
|
|
}
|