forked from RCOSDP/GakuNinLMS-LTI-MC
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: URLの取得に失敗したときビデオ切り替え等に失敗する不具合への対処
- Loading branch information
Showing
4 changed files
with
76 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import getFilePath from "./getFilePath"; | ||
|
||
test("YouTube Video IDが得られる", () => { | ||
expect( | ||
getFilePath({ | ||
providerUrl: "https://www.youtube.com/", | ||
url: "https://www.youtube.com/watch?v=aqz-KE-bpKQ", | ||
}) | ||
).toBe("aqz-KE-bpKQ"); | ||
}); | ||
|
||
test("Vimeo Video IDが得られる", () => { | ||
expect( | ||
getFilePath({ | ||
providerUrl: "https://vimeo.com/", | ||
url: "https://vimeo.com/253989945", | ||
}) | ||
).toBe("253989945"); | ||
}); | ||
|
||
test("Wowzaのファイルパスが得られる", () => { | ||
expect( | ||
getFilePath({ | ||
providerUrl: "https://example/", | ||
url: "https://example/api/v2/wowza/sample.mp4", | ||
}) | ||
).toBe("sample.mp4"); | ||
}); | ||
|
||
test("YouTube Video IDの取得失敗", () => { | ||
expect( | ||
getFilePath({ | ||
providerUrl: "https://www.youtube.com/", | ||
url: "https://www.youtube.com/", | ||
}) | ||
).toBe(undefined); | ||
}); | ||
|
||
test("URLが空", () => { | ||
expect( | ||
getFilePath({ | ||
providerUrl: "https://vimeo.com/", | ||
url: "", | ||
}) | ||
).toBe(undefined); | ||
}); |
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,27 @@ | ||
import getValidUrl from "$utils/getValidUrl"; | ||
|
||
/** | ||
* ビデオリソースURLをv1イベントオブジェクトのfileパラメーターに変換 | ||
* @param e.providerUrl 動画プロバイダーの識別子 | ||
* @param e.url URL | ||
* @return v1イベントオブジェクトのfileパラメーター | ||
*/ | ||
function getFilePath({ | ||
providerUrl, | ||
url, | ||
}: { | ||
providerUrl: string | null; | ||
url: string; | ||
}) { | ||
const validUrl = getValidUrl(url); | ||
// TODO: URLの取得に失敗し "" が得られる不具合が解決すればこの処理はおそらく不要 | ||
if (!validUrl) return; | ||
|
||
if (providerUrl === "https://www.youtube.com/") { | ||
return new URLSearchParams(url.split("?")[1]).get("v") ?? undefined; | ||
} | ||
|
||
return validUrl.pathname.replace(/^\/(?:api\/v2\/wowza\/)?/, ""); | ||
} | ||
|
||
export default getFilePath; |
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 @@ | ||
export { default } from "$server/utils/getValidUrl"; |