Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: WOWZA_EXPIRES_IN が 0 のときアクセスできない問題の修正 #943

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ docker compose down
| `PUBLIC_ACCESS_HASH_ALGORITHM` | 公開 URL のトークン生成に利用するハッシュアルゴリズム (デフォルト: "sha256"、`openssl help` コマンドの "Message Digest commands" の項目に表示される値が利用可能) |
| `PUBLIC_ACCESS_CRYPTO_ALGORITHM` | Wowza 動画と字幕のトークン生成に利用する暗号化アルゴリズム (デフォルト: "aes-256-cbc"、`openssl help` コマンドの "Cipher commands" の項目に表示される値が利用可能) |
| `ACTIVITY_RATE_MIN` | 学習活動の完了とみなす最小の視聴時間の割合 (デフォルト:`0.9`) |
| `VTT_ACCESS_TOKEN_EXPIRES_IN` | 字幕を取得する際のアクセストークンの有効期限 (秒) (デフォルト: `5400`) |

[database_connection_url]: https://www.prisma.io/docs/reference/database-connectors/connection-urls/

Expand Down
4 changes: 4 additions & 0 deletions server/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const PUBLIC_ACCESS_HASH_ALGORITHM =
process.env.PUBLIC_ACCESS_HASH_ALGORITHM ?? "sha256";
const PUBLIC_ACCESS_CRYPTO_ALGORITHM =
process.env.PUBLIC_ACCESS_CRYPTO_ALGORITHM ?? "aes-256-cbc";
const VTT_ACCESS_TOKEN_EXPIRES_IN = Number(
process.env.VTT_ACCESS_TOKEN_EXPIRES_IN ?? "5400"
);

export {
PORT,
Expand Down Expand Up @@ -83,4 +86,5 @@ export {
ZOOM_IMPORT_PUBLIC_DEFAULT_DOMAINS,
PUBLIC_ACCESS_HASH_ALGORITHM,
PUBLIC_ACCESS_CRYPTO_ALGORITHM,
VTT_ACCESS_TOKEN_EXPIRES_IN,
};
13 changes: 10 additions & 3 deletions server/utils/topicResourceToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
WOWZA_EXPIRES_IN,
SESSION_SECRET,
PUBLIC_ACCESS_CRYPTO_ALGORITHM,
VTT_ACCESS_TOKEN_EXPIRES_IN,
} from "$server/utils/env";

const SEPARATOR = "/";
Expand Down Expand Up @@ -50,7 +51,10 @@ export function getWowzaAccessToken(

const value = {
ip,
expired: new Date(new Date().getTime() + WOWZA_EXPIRES_IN * 1000),
expired:
WOWZA_EXPIRES_IN > 0
? new Date(new Date().getTime() + WOWZA_EXPIRES_IN * 1000)
: null,
url,
};
return getAccessToken(value);
Expand All @@ -67,7 +71,8 @@ export function checkWowzaAccessToken(
const value = parseAccessToken(accessToken);
return (
value.ip == ip &&
new Date(value.expired).getTime() > new Date().getTime() &&
(WOWZA_EXPIRES_IN === 0 ||
new Date(value.expired).getTime() > new Date().getTime()) &&
new URL(value.url).pathname == `${API_BASE_PATH}/wowza/${path}`
);
} catch (e) {
Expand All @@ -84,7 +89,9 @@ export function getVttAccessToken(

const value = {
ip,
expired: new Date(new Date().getTime() + WOWZA_EXPIRES_IN * 1000),
expired: new Date(
new Date().getTime() + VTT_ACCESS_TOKEN_EXPIRES_IN * 1000
),
resourceId,
videoTrackId,
};
Expand Down