update
This commit is contained in:
parent
224bdf77ab
commit
31a5271e6e
2 changed files with 12 additions and 1 deletions
|
@ -173,8 +173,10 @@ impl Library {
|
||||||
let lib = self.get_video_paths(dir).await;
|
let lib = self.get_video_paths(dir).await;
|
||||||
|
|
||||||
for path in lib {
|
for path in lib {
|
||||||
|
if !Video::has_path(&path.display().to_string()).await {
|
||||||
Video::insert_path_to_db(&path).await;
|
Video::insert_path_to_db(&path).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log::info!("Finished scanning {dir:?}");
|
log::info!("Finished scanning {dir:?}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,15 @@ impl Video {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn has_path(path: &str) -> bool {
|
||||||
|
sqlx::query("SELECT id FROM videos WHERE path = $1")
|
||||||
|
.bind(path)
|
||||||
|
.fetch_optional(get_pg!())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert_path_to_db(v: &PathBuf) -> Option<Self> {
|
pub async fn insert_path_to_db(v: &PathBuf) -> Option<Self> {
|
||||||
let db = get_pg!();
|
let db = get_pg!();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue