Compare commits
	
		
			2 Commits 
		
	
	
		
			0e543539cf
			...
			86687a7b96
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
									
								
								 | 
						86687a7b96 | |
| 
							
							
								
									
								
								 | 
						f4008e4b9c | 
| 
						 | 
					@ -14,5 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 | 
				
			||||||
    * subscriptions
 | 
					    * subscriptions
 | 
				
			||||||
    * episode changes
 | 
					    * episode changes
 | 
				
			||||||
    * devices
 | 
					    * devices
 | 
				
			||||||
 | 
					    * device sync API
 | 
				
			||||||
* Flexible configuration via a TOML config file, environment variables or CLI
 | 
					* Flexible configuration via a TOML config file, environment variables or CLI
 | 
				
			||||||
  arguments
 | 
					  arguments
 | 
				
			||||||
 | 
					* CLI tooling for interacting with the database
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@ Gpodder, suitable for low-power devices.
 | 
				
			||||||
    * Devices API
 | 
					    * Devices API
 | 
				
			||||||
    * Subscriptions API
 | 
					    * Subscriptions API
 | 
				
			||||||
    * Episode actions API
 | 
					    * Episode actions API
 | 
				
			||||||
 | 
					    * Device synchronisation API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Configuration
 | 
					## Configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,45 @@
 | 
				
			||||||
 | 
					use clap::Subcommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Subcommand)]
 | 
				
			||||||
 | 
					pub enum Command {
 | 
				
			||||||
 | 
					    /// Add devices of a specific user to the same sync group
 | 
				
			||||||
 | 
					    Sync {
 | 
				
			||||||
 | 
					        username: String,
 | 
				
			||||||
 | 
					        devices: Vec<String>,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    /// List the devices for the given user
 | 
				
			||||||
 | 
					    Devices { username: String },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Command {
 | 
				
			||||||
 | 
					    pub fn run(&self, config: &crate::config::Config) -> u8 {
 | 
				
			||||||
 | 
					        let pool = db::initialize_db(config.data_dir.join(crate::DB_FILENAME), true).unwrap();
 | 
				
			||||||
 | 
					        let repo = db::SqliteRepository::from(pool);
 | 
				
			||||||
 | 
					        let store = crate::gpodder::GpodderRepository::new(repo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match self {
 | 
				
			||||||
 | 
					            Self::Sync { username, devices } => {
 | 
				
			||||||
 | 
					                let user = store.get_user(&username).unwrap();
 | 
				
			||||||
 | 
					                store
 | 
				
			||||||
 | 
					                    .update_device_sync_status(
 | 
				
			||||||
 | 
					                        &user,
 | 
				
			||||||
 | 
					                        vec![devices.iter().map(|s| s.as_ref()).collect()],
 | 
				
			||||||
 | 
					                        Vec::new(),
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    .unwrap();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Self::Devices { username } => {
 | 
				
			||||||
 | 
					                let user = store.get_user(&username).unwrap();
 | 
				
			||||||
 | 
					                let devices = store.devices_for_user(&user).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                for device in devices {
 | 
				
			||||||
 | 
					                    println!("{} ({} subscriptions)", device.id, device.subscriptions);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
mod db;
 | 
					mod db;
 | 
				
			||||||
 | 
					mod gpo;
 | 
				
			||||||
mod serve;
 | 
					mod serve;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::path::PathBuf;
 | 
					use std::path::PathBuf;
 | 
				
			||||||
| 
						 | 
					@ -49,6 +50,11 @@ pub enum Command {
 | 
				
			||||||
    Serve,
 | 
					    Serve,
 | 
				
			||||||
    #[command(subcommand)]
 | 
					    #[command(subcommand)]
 | 
				
			||||||
    Db(db::DbCommand),
 | 
					    Db(db::DbCommand),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Perform operations on the database through the Gpodder abstraction, allowing operations
 | 
				
			||||||
 | 
					    /// identical to the ones performed by the API.
 | 
				
			||||||
 | 
					    #[command(subcommand)]
 | 
				
			||||||
 | 
					    Gpo(gpo::Command),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Cli {
 | 
					impl Cli {
 | 
				
			||||||
| 
						 | 
					@ -75,6 +81,7 @@ impl Cli {
 | 
				
			||||||
        match &self.cmd {
 | 
					        match &self.cmd {
 | 
				
			||||||
            Command::Serve => serve::serve(&config),
 | 
					            Command::Serve => serve::serve(&config),
 | 
				
			||||||
            Command::Db(cmd) => cmd.run(&config),
 | 
					            Command::Db(cmd) => cmd.run(&config),
 | 
				
			||||||
 | 
					            Command::Gpo(cmd) => cmd.run(&config),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,10 @@ impl GpodderRepository {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn get_user(&self, username: &str) -> Result<models::User, AuthErr> {
 | 
				
			||||||
 | 
					        self.store.get_user(username)?.ok_or(AuthErr::UnknownUser)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn validate_credentials(
 | 
					    pub fn validate_credentials(
 | 
				
			||||||
        &self,
 | 
					        &self,
 | 
				
			||||||
        username: &str,
 | 
					        username: &str,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue