Skip to content

Commit

Permalink
feat: 合并 Provider 接口定义
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Oct 27, 2019
1 parent 9f6685b commit f197e19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export async function generate(
assert(template, '必须指定 artifact 的 template 属性');
assert(artifact.provider, '必须指定 artifact 的 provider 属性');

const recipeList = artifact.recipe ? artifact.recipe : [artifact.provider];
const combineProviders = artifact.combineProviders || [];
const providerList = [artifact.provider].concat(combineProviders);
const nodeList: PossibleNodeConfigType[] = [];
const nodeNameList: SimpleNodeConfig[] = [];
let customFilters: ProviderConfig['customFilters'];
Expand All @@ -94,7 +95,7 @@ export async function generate(
config.binPath.vmess = config.binPath.v2ray;
}

for (const providerName of recipeList) {
for (const providerName of providerList) {
const filePath = path.resolve(config.providerDir, `${providerName}.js`);

if (!fs.existsSync(filePath)) {
Expand All @@ -119,14 +120,15 @@ export async function generate(
throw err;
}

// Filter 仅使用第一个 Provider 中的定义
if (!netflixFilter) {
netflixFilter = provider.netflixFilter || defaultNetflixFilter;
}
if (!youtubePremiumFilter) {
youtubePremiumFilter = provider.youtubePremiumFilter || defaultYoutubePremiumFilter;
}
if (!customFilters) {
customFilters = provider.customFilters;
customFilters = provider.customFilters || {};
}

nodeConfigList.forEach(nodeConfig => {
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface ArtifactConfig {
readonly name: string;
readonly template: string;
readonly provider: string;
readonly recipe?: readonly string[];
readonly combineProviders?: ReadonlyArray<string>;
readonly customParams?: PlainObjectOf<string|boolean|number>;
readonly proxyGroupModifier?: ProxyGroupModifier;
}
Expand Down

0 comments on commit f197e19

Please sign in to comment.