Skip to content

Commit

Permalink
Add video indexing (#17)
Browse files Browse the repository at this point in the history
* Make user not required for auth middleware, have route fail if needed

* Add new videos route

* Add function for getting videos by video id or user id

* Remove unecessary comment

* Add queue debug statement for tracer

* Have uploads route use the config for upload dir

* Fix path conversion for upload dir

* Update pattern for decoding claims

* Add username as query

* Add video privacy status column

* Add by_username for video get

* Remove fetch user by user id

* Add logic for fetching videos by video id and username

* Added client-side videos page and watch page

* Update vod library to properly handle multi-quality uploads

* Remove random info statement

* Add `all` function for videos

* Update videos routes to be able to stream video
  • Loading branch information
sneakycrow authored Nov 10, 2024
1 parent 033a3fb commit 8947919
Show file tree
Hide file tree
Showing 24 changed files with 944 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ target/
.env*
!.env.example
uploads/
videos/
/videos
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/db/migrations/20241109231211_video_privacy.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Remove the privacy_status column from videos table
ALTER TABLE videos
DROP COLUMN privacy_status;

-- Remove the privacy_status enum type
DROP TYPE privacy_status;
6 changes: 6 additions & 0 deletions packages/db/migrations/20241109231211_video_privacy.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Create enum type for privacy status
CREATE TYPE privacy_status AS ENUM ('private', 'public');

-- Add privacy_status column to videos table with default value of 'public'
ALTER TABLE videos
ADD COLUMN privacy_status privacy_status NOT NULL DEFAULT 'public';
59 changes: 59 additions & 0 deletions packages/db/src/videos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum ProcessingStatus {
}

impl Video {
/// A function for creating new video data in the db
pub async fn create(
pool: &PgPool,
user_id: Uuid,
Expand All @@ -47,4 +48,62 @@ impl Video {
.fetch_one(pool)
.await
}
/// A function for fetching video data from the db by video ID
pub async fn by_id(pool: &PgPool, video_id: &str) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as::<_, Video>(
r#"
SELECT id, user_id, title, raw_video_path, processed_video_path,
processing_status, created_at, updated_at
FROM videos
WHERE id = $1
"#,
)
.bind(video_id)
.fetch_optional(pool)
.await
}
/// A function for getting all user owned videos by user ID
pub async fn by_userid(pool: &PgPool, user_id: Uuid) -> Result<Vec<Self>, sqlx::Error> {
sqlx::query_as::<_, Video>(
r#"
SELECT id, user_id, title, raw_video_path, processed_video_path,
processing_status, created_at, updated_at
FROM videos
WHERE user_id = $1
ORDER BY created_at DESC
"#,
)
.bind(user_id)
.fetch_all(pool)
.await
}
/// A function for getting all user owned videos by user name
pub async fn by_username(pool: &PgPool, username: &str) -> Result<Vec<Self>, sqlx::Error> {
sqlx::query_as::<_, Video>(
r#"
SELECT v.id, v.user_id, v.title, v.raw_video_path, v.processed_video_path,
v.processing_status, v.created_at, v.updated_at
FROM videos v
JOIN users u ON u.id = v.user_id
WHERE u.name = $1
ORDER BY v.created_at DESC
"#,
)
.bind(username)
.fetch_all(pool)
.await
}
/// A function for getting all videos
pub async fn all(pool: &PgPool) -> Result<Vec<Self>, sqlx::Error> {
sqlx::query_as::<_, Video>(
r#"
SELECT id, user_id, title, raw_video_path, processed_video_path,
processing_status, created_at, updated_at
FROM videos
ORDER BY created_at DESC
"#,
)
.fetch_all(pool)
.await
}
}
1 change: 0 additions & 1 deletion packages/queue/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ async fn handle_job(job: Job, db: &Pool<Postgres>) -> Result<(), Error> {
Quality::new(1920, 1080, "5000k", "1080p"),
Quality::new(1280, 720, "2800k", "720p"),
Quality::new(854, 480, "1400k", "480p"),
Quality::new(640, 360, "800k", "360p"),
];

// Process the video
Expand Down
1 change: 1 addition & 0 deletions packages/vod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
tracing = "0.1"
Loading

0 comments on commit 8947919

Please sign in to comment.