|
|
@@ -11,11 +11,11 @@ interface UpdateConfigParams {
|
|
|
|
|
|
export interface PublishProxyAdminConfig {
|
|
|
enabled: boolean;
|
|
|
- cityApiUrl: string;
|
|
|
+ productKey: string;
|
|
|
}
|
|
|
|
|
|
export interface UpdatePublishProxyAdminConfig {
|
|
|
- cityApiUrl?: string;
|
|
|
+ productKey?: string;
|
|
|
}
|
|
|
|
|
|
interface SystemStatus {
|
|
|
@@ -38,7 +38,7 @@ export class SystemService {
|
|
|
async getPublicConfig(): Promise<SystemConfigType> {
|
|
|
const configs = await this.configRepository.find();
|
|
|
const configMap = new Map(configs.map(c => [c.configKey, c.configValue]));
|
|
|
- const cityApiUrl = (configMap.get('publish_proxy_city_api_url') || '').trim();
|
|
|
+ const productKey = (configMap.get('publish_proxy_shenlong_product_key') || '').trim();
|
|
|
|
|
|
return {
|
|
|
allowRegistration: configMap.get('allow_registration') === 'true',
|
|
|
@@ -46,7 +46,7 @@ export class SystemService {
|
|
|
maxUploadSize: 4096 * 1024 * 1024, // 4GB
|
|
|
supportedPlatforms: AVAILABLE_PLATFORM_TYPES,
|
|
|
publishProxy: {
|
|
|
- enabled: Boolean(cityApiUrl),
|
|
|
+ enabled: Boolean(productKey),
|
|
|
provider: 'shenlong',
|
|
|
cities: [],
|
|
|
},
|
|
|
@@ -66,42 +66,30 @@ export class SystemService {
|
|
|
const configs = await this.configRepository.find();
|
|
|
const configMap = new Map(configs.map(c => [c.configKey, c.configValue]));
|
|
|
|
|
|
- const cityApiUrl = (configMap.get('publish_proxy_city_api_url') || '').trim();
|
|
|
+ const productKey = (configMap.get('publish_proxy_shenlong_product_key') || '').trim();
|
|
|
|
|
|
return {
|
|
|
- enabled: Boolean(cityApiUrl),
|
|
|
- cityApiUrl,
|
|
|
+ enabled: Boolean(productKey),
|
|
|
+ productKey,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
async updatePublishProxyAdminConfig(params: UpdatePublishProxyAdminConfig): Promise<void> {
|
|
|
- if (params.cityApiUrl !== undefined) {
|
|
|
- await this.setConfig('publish_proxy_city_api_url', String(params.cityApiUrl || '').trim());
|
|
|
+ if (params.productKey !== undefined) {
|
|
|
+ await this.setConfig('publish_proxy_shenlong_product_key', String(params.productKey || '').trim());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async getPublishProxyCitiesFromApi(): Promise<string[]> {
|
|
|
- const configs = await this.configRepository.find({
|
|
|
- where: { configKey: 'publish_proxy_city_api_url' },
|
|
|
- });
|
|
|
- const cityApiUrl = (configs?.[0]?.configValue || '').trim();
|
|
|
- if (!cityApiUrl) return [];
|
|
|
-
|
|
|
- let responseText = '';
|
|
|
- try {
|
|
|
- const response = await fetch(cityApiUrl, { signal: AbortSignal.timeout(15000) });
|
|
|
- responseText = await response.text();
|
|
|
- } catch {
|
|
|
- return [];
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- const parsed = JSON.parse(responseText);
|
|
|
- const cities = this.extractCitiesFromProxyApiResponse(parsed);
|
|
|
- return Array.from(new Set(cities)).filter(Boolean).sort((a, b) => a.localeCompare(b, 'zh-CN'));
|
|
|
- } catch {
|
|
|
- return [];
|
|
|
+ const regions = await this.regionService.getChinaRegionsFromCsv();
|
|
|
+ const citySet = new Set<string>();
|
|
|
+ for (const province of regions) {
|
|
|
+ for (const city of province.children || []) {
|
|
|
+ const name = String(city.label || '').trim();
|
|
|
+ if (name) citySet.add(name);
|
|
|
+ }
|
|
|
}
|
|
|
+ return Array.from(citySet).sort((a, b) => a.localeCompare(b, 'zh-CN'));
|
|
|
}
|
|
|
|
|
|
async getPublishProxyRegionsFromCsv(): Promise<ChinaRegionOption[]> {
|
|
|
@@ -134,42 +122,4 @@ export class SystemService {
|
|
|
await this.configRepository.save({ configKey: key, configValue: value });
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private extractCitiesFromProxyApiResponse(payload: any): string[] {
|
|
|
- const result: string[] = [];
|
|
|
-
|
|
|
- const pushCity = (value: any) => {
|
|
|
- const city = String(value || '').trim();
|
|
|
- if (city) result.push(city);
|
|
|
- };
|
|
|
-
|
|
|
- if (Array.isArray(payload)) {
|
|
|
- for (const item of payload) {
|
|
|
- if (typeof item === 'string') continue;
|
|
|
- if (item && typeof item === 'object') {
|
|
|
- pushCity((item as any).city ?? (item as any).name ?? (item as any).fullname);
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (!payload || typeof payload !== 'object') return result;
|
|
|
-
|
|
|
- if (Array.isArray((payload as any).cities)) {
|
|
|
- for (const c of (payload as any).cities) pushCity(c);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- const data = (payload as any).data;
|
|
|
- if (Array.isArray(data)) {
|
|
|
- for (const item of data) {
|
|
|
- if (typeof item === 'string') continue;
|
|
|
- if (item && typeof item === 'object') {
|
|
|
- pushCity((item as any).city ?? (item as any).name ?? (item as any).fullname);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|