Skip to content

Commit

Permalink
[Video-Service] feat: updated all video retrieval to include signed U…
Browse files Browse the repository at this point in the history
…RLs for thumbnails and user avatars
  • Loading branch information
rashmod committed Aug 4, 2024
1 parent f899484 commit 901cfdb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/video_service/src/repositories/video.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class VideoRepository {
videoName: video.videoName,
createdAt: video.createdAt,
userId: video.userId,
username: user.name,
name: user.name,
avatarUrl: user.avatarUrl,
})
.from(video)
Expand Down
2 changes: 1 addition & 1 deletion backend/video_service/src/services/media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class MediaService {
});

const url = await getSignedUrlS3(s3Client, command, {
expiresIn: WEEK,
expiresIn: WEEK / 1000,
});

return url;
Expand Down
20 changes: 19 additions & 1 deletion backend/video_service/src/services/video.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ export default class VideoService {
throw new InternalServerError('Failed to fetch videos');
}

return videos;
const videosWithUrls = Promise.all(
videos.map(async (video) => {
// todo show thumbnail through cloudfront
const thumbnailUrl = await MediaService.getThumbnailSignedUrl(
video.thumbnailName
);

const avatarUrl = await (async () => {
if (!video.avatarUrl) return null;
return await MediaService.getThumbnailSignedUrl(
video.avatarUrl
);
})();

return { ...video, thumbnailUrl, avatarUrl };
})
);

return videosWithUrls;
}

static async getVideoById(id: string) {
Expand Down

0 comments on commit 901cfdb

Please sign in to comment.