Skip to content

Commit

Permalink
refactor: 방송 정보 업데이트 API 변경
Browse files Browse the repository at this point in the history
이미지를 전달받았을 때 확장자를 파악하고 이미지 데이터만 저장하도록
변경하였습니다.
  • Loading branch information
JYKIM317 committed Nov 28, 2024
1 parent 39ee9f1 commit b471f33
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions applicationServer/src/live/live.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ export class LiveService {
if (!this.live.data.has(member.broadcast_id)) throw new HttpException('Not Found', HttpStatus.NOT_FOUND);
const memberLiveData = this.live.data.get(member.broadcast_id);

let fileEXT = '.jpg';
if (requestBody.thumbnail) {
const imageData = Buffer.from(requestBody.thumbnail, 'base64');
uploadData(`${memberLiveData.broadcastPath}/static_thumbnail.jpg`, imageData);
const [imageHeader, imageString] = requestBody.thumbnail.split(',');
const dataType = imageHeader.split(':')[1];
fileEXT = dataType.match(/^image\/([a-z0-9\-+]+);base64$/)[0];
const imageData = Buffer.from(imageString, 'base64');
uploadData(`${memberLiveData.broadcastPath}/static_thumbnail.${fileEXT}`, imageData);
}

memberLiveData.title = requestBody.title;
memberLiveData.contentCategory = requestBody.contentCategory;
memberLiveData.moodCategory = requestBody.moodCategory;
memberLiveData.tags = requestBody.tags;
memberLiveData.thumbnailUrl = requestBody.thumbnail
? `https://kr.object.ncloudstorage.com/media-storage/${memberLiveData.broadcastPath}/static_thumbnail.jpg`
? `https://kr.object.ncloudstorage.com/media-storage/${memberLiveData.broadcastPath}/static_thumbnail.${fileEXT}`
: `https://kr.object.ncloudstorage.com/media-storage/${memberLiveData.broadcastPath}/dynamic_thumbnail.jpg`;
}

Expand All @@ -106,7 +110,8 @@ export class LiveService {
this.live.data.get(broadcastId).viewerCount++;

req.on('close', () => {
this.live.data.get(broadcastId).viewerCount--;
const liveData = this.live.data.get(broadcastId);
if (liveData) liveData.viewerCount--;
});

return interval(NOTIFY_LIVE_DATA_INTERVAL_TIME).pipe(map(() => ({ data: this.live.data.get(broadcastId) })));
Expand Down

0 comments on commit b471f33

Please sign in to comment.