ly0303521

给“动感视界”增加点赞功能,并且该点赞数也会触发增加视频生成的次数

... ... @@ -260,11 +260,13 @@ async def toggle_like(item_id: str, user_id: str = Query(..., alias="userId")):
return updated_item
updated_item = video_store.toggle_like(item_id, user_id)
if updated_item: return updated_item
raise HTTPException(status_code=404, detail="Item not found")
updated_item = video_store.toggle_like(item_id, user_id)
if updated_item: return updated_item
if updated_item:
is_liked_after = user_id in updated_item.get("likedBy", [])
if is_liked_after and not is_liked_before:
usage_store.update_bonus(user_id, 1)
elif not is_liked_after and is_liked_before:
usage_store.update_bonus(user_id, -1)
return updated_item
raise HTTPException(status_code=404, detail="Item not found")
@app.get("/usage/{user_id}")
... ...
... ... @@ -6,7 +6,7 @@
},
"11110000": {
"daily_used": 2,
"bonus_count": 0,
"bonus_count": 2,
"last_reset": "2026-01-20"
}
}
\ No newline at end of file
... ...
... ... @@ -16,7 +16,6 @@ const ImageCard: React.FC<ImageCardProps> = ({ image, onClick, onLike, currentUs
const handleLike = (e: React.MouseEvent) => {
e.stopPropagation();
if (isVideo) return; // Liking is disabled for videos for now
onLike(image);
};
... ... @@ -123,7 +122,7 @@ const ImageCard: React.FC<ImageCardProps> = ({ image, onClick, onLike, currentUs
<button
onClick={handleLike}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-full backdrop-blur-md transition-all duration-200 ${image.isLikedByCurrentUser ? 'bg-red-500/80 text-white' : 'bg-white/20 text-white hover:bg-white/30'}`}
title={currentUser ? "Like this image" : "Login to like"}
title={currentUser ? "Like this" : "Login to like"}
>
<Heart size={14} fill={image.isLikedByCurrentUser ? "currentColor" : "none"} />
<span className="text-xs font-bold">{image.likes}</span>
... ... @@ -133,13 +132,19 @@ const ImageCard: React.FC<ImageCardProps> = ({ image, onClick, onLike, currentUs
<div className="flex justify-between items-end">
<div className="text-xs text-gray-300 font-mono flex flex-col gap-1">
<span className="opacity-75">ID: {image.authorId || 'UNKNOWN'}</span>
{image.generationTime && (
<span className="bg-white/10 px-1.5 py-0.5 rounded w-fit flex items-center gap-1"><Hourglass size={10} />{image.generationTime.toFixed(1)}s</span>
)}
</div>
{image.generationTime && (
<div className="flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-white/10 backdrop-blur-md text-white">
<Hourglass size={12} />
<span className="text-xs font-bold">{image.generationTime.toFixed(1)}s</span>
</div>
)}
<button
onClick={handleLike}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-full backdrop-blur-md transition-all duration-200 ${image.isLikedByCurrentUser ? 'bg-red-500/80 text-white' : 'bg-white/20 text-white hover:bg-white/30'}`}
title={currentUser ? "Like this video" : "Login to like"}
>
<Heart size={14} fill={image.isLikedByCurrentUser ? "currentColor" : "none"} />
<span className="text-xs font-bold">{image.likes}</span>
</button>
</div>
)}
</div>
... ...