-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: エンジンの URL を組み立てる部分を関数に切り出す (#2351)
- Loading branch information
Showing
3 changed files
with
32 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** エンジンのURLを構成するパラメータ */ | ||
export type EngineUrlParams = { | ||
protocol: string; // `http:`など | ||
hostname: string; // `example.com`など | ||
port: string; // `50021`など。空文字列もありえる。 | ||
pathname: string; // `/engine`など。空文字列もありえる。 | ||
}; | ||
|
||
/** | ||
* URLを構成するパラメータから、VOICEVOXエディタが初期から想定しているURL文字列を組み立てる。 | ||
* pathnameが空文字の場合は末尾にスラッシュを付与しない、などがビルトインのURLクラスと異なる。 | ||
*/ | ||
export function createEngineUrl(params: EngineUrlParams) { | ||
const { protocol, hostname, port, pathname } = params; | ||
const url = new URL(`${protocol}//${hostname}`); // NOTE: URLを正規化する | ||
url.port = port; | ||
return `${url.origin}${pathname}`; // NOTE: URLインターフェースは"pathname"が空文字でも"/"を付けるので手動で結合する。 | ||
} |
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