View

TIL | NestJS_스트리밍 횟수 카운트

Melody:) 2021. 10. 22. 16:49

구현기능

검증자가 해당 녹음파일을 검증하기 위해서는 해당 녹음파일을 재생한 횟수가 1회 이상 되어야 한다.

따라서 녹음파일을 스트리밍 한 횟수를 카운트 하기위한 기능을 구현하고자 한다.

 

고려사항

1️⃣ 재생버튼을 누른것 만으로 voice의 verify status를 재생횟수 0으로 먼저 생성하고,  재생이 모두 완료 된 후 재생횟수를 1로 업데이트 할 것인가?
(ex.  id = 1)

2️⃣ 재생을 처음부터 끝까지 완료 하였을 때, 엔드포인트로 접근하여 voice의 verify status를 재생횟수(default =1)를 생성할것인가?(ex.  id = 2)

이것은 우리가 음원 회사의 스트리밍 횟수 카운트에 쓰이는 기술과 동일할 것으로 보인다.

좀더 자료를 찾아 본뒤 적용해보아야겠다.

지금은 2️⃣번과 같은 방법으로 구현해놓았다.

 


Voice.controller

    @Post(':voice_id/play_count')
    async  playCountOfVoice(@Param('voice_id') voice_id:number, @Query('user_id') user_id:number): Promise<any>{
        return await this.voiceService.playCountOfVoice(voice_id, user_id);
    }

Voice.service

    async playCountOfVoice (voice_id:number, user_id: number):Promise<any> {

      const voiceStatus = await this.prisma.voiceVeriftyStatus.create({
        data:{
          voice : {connect : {id : voice_id}},
          user  : {connect : {id : user_id}},
        },
      })
      return voiceStatus;
    }

model VoiceVeriftyStatus

model VoiceVeriftyStatus {
    id      	    Int       @default(autoincrement()) @id
    voice	        Voice     @relation(fields: [voiceId], references: [id])
    voiceId	        Int       
    verifyStatus 	Boolean   @default(false) 
    user	        User      @relation(fields: [userId], references: [id])       
    userId	        Int           
    playCount	    Int       @default(1)    
    dateOfCreated	DateTime  @db.Timestamptz(3) @default(now())
    dateOfUpdated	DateTime? @db.Timestamptz(3) @updatedAt
    
    @@map("voice_verifty_status")
}

 

Share Link
reply
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31