A decentralized music tracking and discovery platform built on AT Protocol 🎵

fix empty googledrive parent dir value

+84 -44
+8 -8
crates/dropbox/src/repo/dropbox_directory.rs
··· 1 - use sqlx::{Pool, Postgres}; 2 1 use crate::{types::file::Entry, xata::dropbox_diretory::DropboxDirectory}; 2 + use sqlx::{Pool, Postgres}; 3 3 4 4 pub async fn create_dropbox_directory( 5 5 pool: &Pool<Postgres>, ··· 7 7 dropbox_id: &str, 8 8 parent_dir: &str, 9 9 ) -> Result<(), sqlx::Error> { 10 - let results: Vec<DropboxDirectory> = sqlx::query_as( 11 - r#" 10 + let results: Vec<DropboxDirectory> = sqlx::query_as( 11 + r#" 12 12 SELECT * 13 13 FROM dropbox_directories 14 14 WHERE dropbox_id = $1 ··· 21 21 .fetch_all(pool) 22 22 .await?; 23 23 24 - let parent_id = results.first().map(|d| d.xata_id.clone()); 24 + let parent_id = results.first().map(|d| d.xata_id.clone()); 25 25 26 - sqlx::query( 27 - r#" 26 + sqlx::query( 27 + r#" 28 28 INSERT INTO dropbox_directories ( 29 29 dropbox_id, 30 30 name, ··· 44 44 .execute(pool) 45 45 .await?; 46 46 47 - Ok(()) 48 - } 47 + Ok(()) 48 + }
+6 -2
crates/dropbox/src/scan.rs
··· 22 22 consts::AUDIO_EXTENSIONS, 23 23 crypto::decrypt_aes_256_ctr, 24 24 repo::{ 25 - dropbox_directory::create_dropbox_directory, dropbox_path::create_dropbox_path, dropbox_token::{find_dropbox_refresh_token, find_dropbox_refresh_tokens}, track::get_track_by_hash 25 + dropbox_directory::create_dropbox_directory, 26 + dropbox_path::create_dropbox_path, 27 + dropbox_token::{find_dropbox_refresh_token, find_dropbox_refresh_tokens}, 28 + track::get_track_by_hash, 26 29 }, 27 30 token::generate_token, 28 31 types::file::{Entry, EntryList}, ··· 291 294 let parent_path = Path::new(&path) 292 295 .parent() 293 296 .map(|p| p.to_string_lossy().to_string()); 294 - let status = create_dropbox_path(&pool, &entry, &track, &dropbox_id, parent_path).await; 297 + let status = 298 + create_dropbox_path(&pool, &entry, &track, &dropbox_id, parent_path).await; 295 299 println!("status: {:?}", status); 296 300 297 301 // TODO: publish file metadata to nats
+10 -13
crates/googledrive/src/repo/google_drive_directory.rs
··· 1 - use sqlx::{Pool, Postgres}; 2 1 use crate::{types::file::File, xata::google_drive_directory::GoogleDriveDirectory}; 2 + use sqlx::{Pool, Postgres}; 3 3 4 4 pub async fn create_google_drive_directory( 5 5 pool: &Pool<Postgres>, ··· 15 15 WHERE google_drive_id = $1 16 16 AND file_id = $2 17 17 LIMIT 1 18 - "# 18 + "#, 19 19 ) 20 20 .bind(google_drive_id) 21 21 .bind(parent_id) 22 22 .fetch_all(pool) 23 23 .await?; 24 - if results.is_empty() { 25 - None 26 - } else { 27 - Some(results[0].clone()) 28 - } 24 + if results.is_empty() { 25 + None 26 + } else { 27 + Some(results[0].clone()) 28 + } 29 29 } else { 30 30 None 31 31 }; ··· 35 35 format!("{}/{}", p.path.trim_end_matches('/'), file.name), 36 36 Some(p.xata_id), 37 37 ), 38 - None => ( 39 - format!("/{}", file.name), 40 - None, 41 - ), 38 + None => (format!("/{}", file.name), None), 42 39 }; 43 40 44 41 sqlx::query( ··· 52 49 ) 53 50 VALUES ($1, $2, $3, $4, $5) 54 51 ON CONFLICT DO NOTHING 55 - "# 52 + "#, 56 53 ) 57 54 .bind(google_drive_id) 58 55 .bind(&file.name) ··· 63 60 .await?; 64 61 65 62 Ok(()) 66 - } 63 + }
+16 -9
crates/googledrive/src/repo/google_drive_path.rs
··· 1 1 use sqlx::{Pool, Postgres}; 2 2 3 - use crate::{types::file::File, xata::{google_drive_directory::GoogleDriveDirectory, track::Track}}; 3 + use crate::{ 4 + types::file::File, 5 + xata::{google_drive_directory::GoogleDriveDirectory, track::Track}, 6 + }; 4 7 5 8 pub async fn create_google_drive_path( 6 9 pool: &Pool<Postgres>, ··· 9 12 google_drive_id: &str, 10 13 parent_dir: &str, 11 14 ) -> Result<(), sqlx::Error> { 12 - let parent_dir: Vec<GoogleDriveDirectory> = sqlx::query_as( 13 - r#" 15 + let parent_dir = if parent_dir.is_empty() { 16 + None 17 + } else { 18 + let parent_dirs: Vec<GoogleDriveDirectory> = sqlx::query_as( 19 + r#" 14 20 SELECT * 15 21 FROM google_drive_directories 16 22 WHERE google_drive_id = $1 17 23 AND file_id = $2 18 24 LIMIT 1 19 25 "#, 20 - ) 21 - .bind(google_drive_id) 22 - .bind(parent_dir) 23 - .fetch_all(pool) 24 - .await?; 26 + ) 27 + .bind(google_drive_id) 28 + .bind(parent_dir) 29 + .fetch_all(pool) 30 + .await?; 25 31 26 - let parent_dir = parent_dir.first().map(|d| d.clone().xata_id); 32 + parent_dirs.first().map(|d| d.xata_id.clone()) 33 + }; 27 34 28 35 let result = sqlx::query( 29 36 r#"
+29 -6
crates/googledrive/src/scan.rs
··· 21 21 consts::AUDIO_EXTENSIONS, 22 22 crypto::decrypt_aes_256_ctr, 23 23 repo::{ 24 - google_drive_directory::create_google_drive_directory, google_drive_path::create_google_drive_path, google_drive_token::{find_google_drive_refresh_token, find_google_drive_refresh_tokens}, track::get_track_by_hash 24 + google_drive_directory::create_google_drive_directory, 25 + google_drive_path::create_google_drive_path, 26 + google_drive_token::{find_google_drive_refresh_token, find_google_drive_refresh_tokens}, 27 + track::get_track_by_hash, 25 28 }, 26 29 token::generate_token, 27 30 types::file::{File, FileList}, ··· 103 106 if file.mime_type == "application/vnd.google-apps.folder" { 104 107 println!("Scanning folder: {}", file.name.bright_green()); 105 108 106 - create_google_drive_directory(&pool, &file, &google_drive_id, parent_drive_file_id.as_deref()).await?; 109 + create_google_drive_directory( 110 + &pool, 111 + &file, 112 + &google_drive_id, 113 + parent_drive_file_id.as_deref(), 114 + ) 115 + .await?; 107 116 108 117 // TODO: publish folder metadata to nats 109 118 ··· 296 305 match track { 297 306 Some(track) => { 298 307 println!("Track exists: {}", title.bright_green()); 299 - let status = 300 - create_google_drive_path(&pool, &file, &track, &google_drive_id, &file_id).await?; 308 + let parent_drive_id = parent_drive_file_id.as_deref(); 309 + let status = create_google_drive_path( 310 + &pool, 311 + &file, 312 + &track, 313 + &google_drive_id, 314 + parent_drive_id.unwrap_or(""), 315 + ) 316 + .await?; 301 317 302 318 println!("status: {:?}", status); 303 319 // TODO: publish file metadata to nats ··· 347 363 348 364 let track = get_track_by_hash(&pool, &hash).await?; 349 365 if let Some(track) = track { 350 - let status = 351 - create_google_drive_path(&pool, &file, &track, &google_drive_id, &file_id).await; 366 + let parent_drive_id = parent_drive_file_id.as_deref(); 367 + let status = create_google_drive_path( 368 + &pool, 369 + &file, 370 + &track, 371 + &google_drive_id, 372 + parent_drive_id.unwrap_or(""), 373 + ) 374 + .await; 352 375 353 376 println!("status: {:?}", status); 354 377
+1 -1
crates/raichu/src/lib.rs
··· 5 5 use std::f32::consts::PI; 6 6 use std::io::Cursor; 7 7 use symphonia::core::audio::SampleBuffer; 8 - use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL}; 8 + use symphonia::core::codecs::{CODEC_TYPE_NULL, DecoderOptions}; 9 9 use symphonia::core::formats::FormatOptions; 10 10 use symphonia::core::io::{MediaSource, MediaSourceStream}; 11 11 use symphonia::core::meta::MetadataOptions;
+4 -2
crates/scrobbler/src/scrobbler.rs
··· 492 492 493 493 let spotify_user = repo::spotify_account::get_spotify_account(pool, &did).await?; 494 494 if let Some(spotify_user) = spotify_user { 495 - if cache.get(&format!("{}:current", spotify_user.email))?.is_some() { 495 + if cache 496 + .get(&format!("{}:current", spotify_user.email))? 497 + .is_some() 498 + { 496 499 println!( 497 500 "{} {} - {}, currently scrobbling, skipping", 498 501 "Currently scrobbling: ".yellow(), ··· 512 515 ); 513 516 return Ok(()); 514 517 } 515 - 516 518 517 519 // set cache for 5 seconds to avoid duplicate scrobbles 518 520 cache.setex(
+10 -3
crates/spotify/src/main.rs
··· 205 205 email.bright_green(), 206 206 e.to_string().bright_red() 207 207 ); 208 - match rt.block_on(nc.publish("rocksky.spotify.user", email.clone().into())) { 209 - Ok(_) => {}, 208 + match rt 209 + .block_on(nc.publish("rocksky.spotify.user", email.clone().into())) 210 + { 211 + Ok(_) => {} 210 212 Err(e) => { 211 213 println!( 212 214 "{} Error publishing message to restart thread: {}", ··· 697 699 &result.refresh_token, 698 700 &hex::decode(env::var("SPOTIFY_ENCRYPTION_KEY")?)?, 699 701 )?; 700 - user_tokens.push((result.email.clone(), token, result.did.clone(), result.user_id.clone())); 702 + user_tokens.push(( 703 + result.email.clone(), 704 + token, 705 + result.did.clone(), 706 + result.user_id.clone(), 707 + )); 701 708 } 702 709 703 710 Ok(user_tokens)