|
1 | 1 | import type { ProgressResult } from '@clack/prompts' |
2 | 2 | import type { UserProviderConfig, UserProviderMultiConfig } from './config' |
3 | | -import type { OSSFile, Provider, TaskResult, UploadOptions, WorkerMessage } from './types' |
| 3 | +import type { OSSFile, Provider, ProviderConfigItem, TaskResult, UploadOptions, WorkerMessage } from './types' |
4 | 4 | import fs from 'node:fs' |
5 | 5 | import os from 'node:os' |
6 | 6 | import path from 'node:path' |
@@ -33,16 +33,18 @@ export async function upload(configFile?: string): Promise<void> { |
33 | 33 | provider = (config as UserProviderConfig).provider |
34 | 34 | } |
35 | 35 | else if (Reflect.has(config, 'providers')) { |
| 36 | + let providerItem: ProviderConfigItem | undefined |
| 37 | + |
36 | 38 | const providers = (config as UserProviderMultiConfig).providers |
37 | 39 | if (providers.length === 1) { |
38 | | - provider = providers[0].provider |
| 40 | + providerItem = providers[0] |
39 | 41 | } |
40 | 42 | else if (providers.length > 1) { |
41 | 43 | // for ci |
42 | 44 | if (process.env.OSSX_CI_PROVIDER_TAG) { |
43 | 45 | const matched = providers.find(item => item.tag === process.env.OSSX_CI_PROVIDER_TAG) |
44 | 46 | if (matched) { |
45 | | - provider = matched.provider |
| 47 | + providerItem = matched |
46 | 48 | log.step(`Using provider ${ansis.cyan.bold(matched.tag)} from environment variable ${ansis.gray('OSSX_CI_PROVIDER_TAG')}`) |
47 | 49 | } |
48 | 50 | else { |
@@ -76,7 +78,16 @@ export async function upload(configFile?: string): Promise<void> { |
76 | 78 | return |
77 | 79 | } |
78 | 80 |
|
79 | | - provider = providers.find(item => item.tag === selected)?.provider |
| 81 | + providerItem = providers.find(item => item.tag === selected) |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if (providerItem) { |
| 86 | + provider = providerItem.provider |
| 87 | + |
| 88 | + // 如果 providerItem 中包含 destination 配置,则覆盖全局配置 |
| 89 | + if (providerItem.destination) { |
| 90 | + config.destination = providerItem.destination |
80 | 91 | } |
81 | 92 | } |
82 | 93 | } |
|
0 commit comments