From 098bdb94fc6bd09f0a3eaafd8ac57873f5ab6f4c Mon Sep 17 00:00:00 2001 From: Ryo Igarashi Date: Wed, 9 Nov 2022 18:45:14 +0900 Subject: [PATCH 1/2] fix: Add missing url in performer insertion --- .../@neet/vschedule-api/src/adapters/dal/PerformerRepository.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@neet/vschedule-api/src/adapters/dal/PerformerRepository.ts b/packages/@neet/vschedule-api/src/adapters/dal/PerformerRepository.ts index 7c6a2fa9..28dad241 100644 --- a/packages/@neet/vschedule-api/src/adapters/dal/PerformerRepository.ts +++ b/packages/@neet/vschedule-api/src/adapters/dal/PerformerRepository.ts @@ -30,6 +30,7 @@ export class PerformerRepository implements IPerformerRepository { name: performer.name.value, description: unwrap(performer.description), color: performer.color.hex(), + url: performer.url?.toString(), youtubeChannelId: unwrap(performer.youtubeChannelId), twitterUsername: unwrap(performer.twitterUsername), avatarId: @@ -70,6 +71,7 @@ export class PerformerRepository implements IPerformerRepository { name: performer.name.value, color: performer.color.hex(), description: unwrap(performer.description), + url: performer.url?.toString(), youtubeChannelId: unwrap(performer.youtubeChannelId), twitterUsername: unwrap(performer.twitterUsername), avatarId: From 6e1d1c45a068411f42e332687675cbc3f7122375 Mon Sep 17 00:00:00 2001 From: Ryo Igarashi Date: Wed, 9 Nov 2022 19:02:47 +0900 Subject: [PATCH 2/2] fix: Handle startedAt / endedAt as nullable --- .../src/app/use-cases/CreateStream.ts | 4 ++-- .../src/infra/services/YouTubeApiService.ts | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/@neet/vschedule-api/src/app/use-cases/CreateStream.ts b/packages/@neet/vschedule-api/src/app/use-cases/CreateStream.ts index 930df3a4..30457a24 100644 --- a/packages/@neet/vschedule-api/src/app/use-cases/CreateStream.ts +++ b/packages/@neet/vschedule-api/src/app/use-cases/CreateStream.ts @@ -91,8 +91,8 @@ export class CreateStream { title: video.title, url: new URL(video.url), description: video.description, - startedAt: dayjs(video.startedAt), - endedAt: dayjs(video.endedAt), + startedAt: video.startedAt != null ? dayjs(video.startedAt) : dayjs(), + endedAt: video.endedAt != null ? dayjs(video.endedAt) : null, ownerId: performer.id, castIds: casts.map((cast) => cast.id), thumbnail, diff --git a/packages/@neet/vschedule-api/src/infra/services/YouTubeApiService.ts b/packages/@neet/vschedule-api/src/infra/services/YouTubeApiService.ts index 9a6558f7..81dfc785 100644 --- a/packages/@neet/vschedule-api/src/infra/services/YouTubeApiService.ts +++ b/packages/@neet/vschedule-api/src/infra/services/YouTubeApiService.ts @@ -66,13 +66,31 @@ export class YoutubeApiService implements IYoutubeApiService { video.snippet.description == null || video.snippet.publishedAt == null || video.snippet.thumbnails?.maxres?.url == null - // video.liveStreamingDetails?.actualStartTime == null ) { throw new Error( `Either videoId or publishedAt or actualStartTime is null`, ); } + const startedAt = + video.liveStreamingDetails?.actualStartTime ?? + video.liveStreamingDetails?.scheduledStartTime; + + const endedAt = + video.liveStreamingDetails?.actualEndTime ?? + video.liveStreamingDetails?.scheduledEndTime; + + if (startedAt == null) { + this._logger.error( + `Failed to infer start time. Both actualStartTime and scheduledStartTime were null`, + { videoId, liveStreamingDetails: video.liveStreamingDetails }, + ); + + throw new Error( + `Failed to infer start time. Both actualStartTime and scheduledStartTime were null`, + ); + } + return { id: video.id, title: video.snippet.title, @@ -81,8 +99,8 @@ export class YoutubeApiService implements IYoutubeApiService { url: `https://www.youtube.com/watch?v=${video.id}`, channelId: video.snippet.channelId, publishedAt: video.snippet.publishedAt, - startedAt: video.liveStreamingDetails?.actualStartTime, - endedAt: video.liveStreamingDetails?.actualEndTime ?? undefined, + startedAt, + endedAt, }; }