-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gateway): 支持批量转换 rewrite-remote 中的 URL
- Loading branch information
Showing
7 changed files
with
367 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { URL } from 'url'; | ||
|
||
export const transformQxRewriteRemote = (str: string, publicUrl: string, deviceIds?: ReadonlyArray<string>): string => { | ||
return str.split('\n') | ||
.map(item => { | ||
if ( | ||
item.startsWith('#') || | ||
item.startsWith('//') || | ||
item.trim() === '' | ||
) { | ||
return item; | ||
} | ||
|
||
const rule = item.split(' '); | ||
|
||
if (rule.indexOf('script-response-body') > -1) { | ||
const scriptPath = rule[3]; | ||
const apiEndpoint = new URL(publicUrl); | ||
apiEndpoint.pathname = '/qx-script'; | ||
apiEndpoint.searchParams.set('url', `${scriptPath}`); | ||
|
||
if (deviceIds) { | ||
apiEndpoint.searchParams.set('id', deviceIds.join(',')); | ||
} | ||
|
||
rule[3] = apiEndpoint.toString(); | ||
|
||
return rule.join(' '); | ||
} | ||
|
||
return item; | ||
}) | ||
.join('\n') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.