feat: add the view graph on tiktok
This commit is contained in:
@@ -77,6 +77,7 @@ export async function GET(req: NextRequest) {
|
||||
followers: true,
|
||||
likes: true,
|
||||
videoCount: true,
|
||||
views: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -88,7 +89,7 @@ export async function POST(req: NextRequest) {
|
||||
if (!userId) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
const body = await req.json();
|
||||
const { followers, likes, videoCount, displayName, openId } = body;
|
||||
const { followers, likes, videoCount, views, displayName, openId } = body;
|
||||
|
||||
if (followers === undefined) {
|
||||
return NextResponse.json({ error: "Champ 'followers' requis" }, { status: 400 });
|
||||
@@ -115,7 +116,7 @@ export async function POST(req: NextRequest) {
|
||||
followers: followers ?? 0,
|
||||
likes: likes ?? 0,
|
||||
videoCount: videoCount ?? 0,
|
||||
views: 0,
|
||||
views: views ?? 0,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ export async function GET() {
|
||||
followers: 124,
|
||||
likes: 856,
|
||||
videoCount: 1,
|
||||
views: 3432,
|
||||
profileViews: 287,
|
||||
displayName: "CrowMate studio",
|
||||
avatarUrl: "",
|
||||
plan: (user as any)?.plan ?? "free",
|
||||
@@ -56,8 +58,7 @@ export async function GET() {
|
||||
|
||||
try {
|
||||
const stats = await fetchUserStats(accessToken, openId);
|
||||
|
||||
// Upsert TrackedAccount + snapshot automatique
|
||||
|
||||
try {
|
||||
let account = await prisma.trackedAccount.findFirst({
|
||||
where: { userId, platform: "tiktok" },
|
||||
@@ -78,14 +79,12 @@ export async function GET() {
|
||||
followers: stats.followers ?? 0,
|
||||
likes: stats.likes ?? 0,
|
||||
videoCount: stats.videoCount ?? 0,
|
||||
views: 0,
|
||||
views: stats.views ?? 0,
|
||||
},
|
||||
});
|
||||
} catch (snapshotErr) {
|
||||
console.error("[TikTok snapshot save error]", snapshotErr);
|
||||
}
|
||||
|
||||
// Inclure le plan dans la réponse
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
return NextResponse.json({ ...stats, plan: (user as any)?.plan ?? "free" });
|
||||
} catch (err) {
|
||||
|
||||
@@ -11,6 +11,7 @@ interface TikTokStats {
|
||||
followers: number;
|
||||
likes: number;
|
||||
videoCount: number;
|
||||
views: number;
|
||||
displayName: string;
|
||||
avatarUrl: string;
|
||||
plan: "free" | "pro" | "elite" | "team";
|
||||
@@ -120,7 +121,7 @@ export default function TikTokPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 xl:grid-cols-4 gap-4 mb-8">
|
||||
<div className="grid grid-cols-2 xl:grid-cols-5 gap-4 mb-8">
|
||||
<StatCard
|
||||
label="Followers"
|
||||
value={stats.followers.toLocaleString("fr-FR")}
|
||||
@@ -139,6 +140,12 @@ export default function TikTokPage() {
|
||||
sub="Vidéos au total"
|
||||
accent="blue"
|
||||
/>
|
||||
<StatCard
|
||||
label="Vues vidéos"
|
||||
value={stats.views.toLocaleString("fr-FR")}
|
||||
sub="Vues totales des vidéos"
|
||||
accent="green"
|
||||
/>
|
||||
<StatCard
|
||||
label="Ratio likes/vidéo"
|
||||
value={stats.videoCount > 0 ? Math.round(stats.likes / stats.videoCount).toLocaleString("fr-FR") : "—"}
|
||||
|
||||
Reference in New Issue
Block a user