ossConfigService.js
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import httpClient from '../plugin/axios/httpClient'
class OssConfigService {
/**
* 从配置服务获取OSS基础配置并动态设置baseURL
* @returns {Promise<Object>} OSS配置对象
* @throws {Error} 当获取配置失败时抛出错误
*/
static async fetchBaseConfig() {
try {
// 使用封装后的httpClient获取基础配置
const config = await httpClient.get('https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsk-oss-config', {
baseURL: '' // 使用完整URL,覆盖默认baseURL
})
const baseConfig = config.data
// 如果配置中包含baseURL,则动态设置
if (baseConfig && baseConfig.axios && baseConfig.axios.baseURL) {
httpClient.setBaseURL(baseConfig.axios.baseURL)
}
return baseConfig
} catch (error) {
console.error('获取基础配置失败:', error)
throw error
}
}
/**
* 从接口获取OSS基础配置
* @returns {Promise<Object>} OSS配置对象
* @throws {Error} 当获取配置失败时抛出错误
*/
static async fetchApiConfig(bucketName, systemSource = 'dj') {
// 使用封装后的httpClient
const config = await httpClient.post('/rop-dj-script/router/dj.api.script.common.aliyun.oss.acs.sts.credentials/1.0.0?bucketName=' + bucketName + '&systemSource=' + systemSource, { bucketName: bucketName, systemSource: systemSource })
// 验证配置结构
if (!config) {
throw new Error('无效的OSS配置格式')
}
return config.data
}
}
export default OssConfigService