jbilcke-hf HF staff commited on
Commit
e657a34
1 Parent(s): 1a3c954

prevent people from liking multiple times.. lol

Browse files
Files changed (1) hide show
  1. src/app/server/actions/stats.ts +11 -0
src/app/server/actions/stats.ts CHANGED
@@ -117,6 +117,17 @@ export async function rateVideo(videoId: string, liked: boolean, apiKey: string)
117
  const user = await whoAmI({ credentials }) as unknown as WhoAmIUser
118
 
119
  const hasLiked = await redis.get<boolean>(`users:${user.id}:activity:videos:${videoId}:liked`)
 
 
 
 
 
 
 
 
 
 
 
120
  const hasAlreadyRatedAndDifferently = hasLiked !== null && liked !== hasLiked
121
 
122
  await redis.set(`users:${user.id}:activity:videos:${videoId}:liked`, liked)
 
117
  const user = await whoAmI({ credentials }) as unknown as WhoAmIUser
118
 
119
  const hasLiked = await redis.get<boolean>(`users:${user.id}:activity:videos:${videoId}:liked`)
120
+
121
+ const hasAlreadyRatedTheSame = hasLiked !== null && liked === hasLiked
122
+
123
+ if (hasAlreadyRatedTheSame) {
124
+ return {
125
+ numberOfLikes: await redis.get(`videos:${videoId}:stats:likes`) || 0,
126
+ numberOfDislikes: await redis.get(`videos:${videoId}:stats:likes`) || 0,
127
+ isLikedByUser: liked,
128
+ isDislikedByUser: !liked
129
+ }
130
+ }
131
  const hasAlreadyRatedAndDifferently = hasLiked !== null && liked !== hasLiked
132
 
133
  await redis.set(`users:${user.id}:activity:videos:${videoId}:liked`, liked)