Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/barcode8/VideoHub/llms.txt

Use this file to discover all available pages before exploring further.

VideoHub provides a dashboard endpoint for channel analytics and a dedicated view tracking endpoint for recording when users watch videos. Together these two endpoints power real-time channel growth metrics and accurate per-video view counts across the platform.

GET /api/v1/dashboard/stats/:channelId

Returns aggregate statistics for a channel — total subscribers, published video count, cumulative views, and total likes. This endpoint requires no authentication and is safe to call from a public channel page. The controller queries the Subscription collection for subscriber count, then runs a MongoDB aggregation pipeline across the channel’s published Video documents. Each video is joined with the likes collection so that per-video like counts can be summed into a single channel-wide total. All four counters default to 0 when the channel has no published videos.

Path Parameters

channelId
string
required
The MongoDB ObjectId of the channel owner whose stats you want to retrieve. Must be a valid 24-character hex ObjectId.

Example Request

curl http://localhost:5000/api/v1/dashboard/stats/64a1b2c3d4e5f6789abc1234

Example Response

{
  "statusCode": 200,
  "data": {
    "totalSubscribers": 142,
    "totalVideos": 8,
    "totalViews": 3891,
    "totalLikes": 215
  },
  "message": "Channel stats fetched successfully",
  "success": true
}

Response Fields

totalSubscribers
number
Number of users currently subscribed to this channel. Counted directly from the Subscription collection using the channelId.
totalVideos
number
Number of videos owned by this channel that have isPublished: true. Draft or unpublished videos are excluded.
totalViews
number
Sum of the views field across all published videos. This is the authoritative view count as stored on each Video document — it is incremented by the view tracking endpoint below.
totalLikes
number
Total number of likes across all published videos owned by this channel. Computed by joining each video with the likes collection inside the aggregation pipeline.

Errors

StatusCondition
400channelId is missing from the path.
400channelId is present but is not a valid MongoDB ObjectId.

View Tracking

VideoHub records individual video views through a dedicated endpoint that deduplicates views per user ID or IP address within a 24-hour window. When a new unique view is recorded, the views counter on the Video document is atomically incremented, which is the value surfaced by the dashboard stats endpoint above.

POST /api/v1/view/:videoId

Records that the currently authenticated user has watched a video. The endpoint builds a query on videoId plus an $or condition matching either the authenticated user’s ID or the request’s IP address against existing View documents. If any matching view is found (view documents are TTL-indexed to expire after 86,400 seconds), the existing record is returned without incrementing the counter. Otherwise a new View document is created, the video’s views field is incremented by 1, and the updated count is returned. Authentication required. Include the access token in the Authorization header.

Path Parameters

videoId
string
required
The MongoDB ObjectId of the video being watched. Must be a valid 24-character hex ObjectId.

Example Request

curl -X POST http://localhost:5000/api/v1/view/64a1b2c3d4e5f6789abc5678 \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Example Response — New View

{
  "statusCode": 200,
  "data": {
    "views": 3892
  },
  "message": "View recorded successfully",
  "success": true
}

Example Response — Duplicate View (within 24 h)

{
  "statusCode": 200,
  "data": {
    "_id": "64b9f3a1c2d7e8901abc4321",
    "video": "64a1b2c3d4e5f6789abc5678",
    "user": "64a1b2c3d4e5f6789abc9999",
    "ipAddress": "203.0.113.42",
    "createdAt": "2024-07-15T10:23:00.000Z",
    "updatedAt": "2024-07-15T10:23:00.000Z"
  },
  "message": "View already recorded in the past 24h",
  "success": true
}

Errors

StatusCondition
400videoId is missing from the path.
400videoId is present but is not a valid MongoDB ObjectId.
404No video found with the given videoId.
401Access token is missing or invalid.
The frontend calls this endpoint automatically when a video starts playing — you do not need to trigger it manually in normal playback flows. View deduplication is enforced per user ID or IP address: if either matches an existing View document for the same video within 24 hours, no additional count is recorded. The views field on the Video model is the authoritative counter and is the same value aggregated by GET /api/v1/dashboard/stats/:channelId.

Build docs developers (and LLMs) love