//! Hosted projects: the vcs protocol client. (Filled in with the server.) use anyhow::Result; use vcs_core::Id; use vcs_core::version::Version; use crate::app::App; use crate::db::{Change, Db, Project}; use crate::host::{Host, LandRequest, Landed}; use crate::objects::Store; use crate::out::Fail; pub struct Remote { pub api: String, } impl Remote { pub fn for_project(project: &Project) -> Remote { Remote { api: project.api.clone().unwrap_or_default() } } pub fn fetch_change(&self, _db: &Db, _store: &Store, _project: &Project, _prefix: &str) -> Result> { Ok(None) } pub fn fetch_saves(&self, _db: &Db, _store: &Store, _project: &Project, _change: &Change) -> Result<()> { Ok(()) } } impl Host for Remote { fn refresh(&self, db: &Db, _store: &Store, project: &Project) -> Result> { db.latest_version(&project.id) } fn fetch_tree(&self, _store: &Store, _project: &Project, _tree: &Id, _have: Option<&Id>) -> Result<()> { Ok(()) } fn land(&self, _db: &Db, _store: &Store, _project: &Project, _request: &LandRequest) -> Result { Err(anyhow::anyhow!("hosted projects aren't available yet")) } } /// The signed-in account for a project's host: (name, email). pub fn account(_project: &Project) -> Option<(String, String)> { None } pub fn project(_app: &App, target: &str) -> Result { Err(Fail::new("not_found", format!("can't reach {target}")).state("nothing changed")) } /// Changes this person can see in the project: local ones plus the host's. pub fn visible_changes(app: &App, project: &Project) -> Result> { app.db.changes(&project.id) } pub fn access_change(_app: &App, _s: &crate::app::Session, _target: &str, _who: Vec, _edit: bool) -> crate::out::Out { Err(Fail::new("bad_usage", "sharing changes needs a hosted project").state("nothing changed")) } /// The host's path rules: (path, who). pub fn path_rules(_app: &App, _project: &Project) -> Result)>> { Ok(Vec::new()) } pub fn set_path_rule(_app: &App, _s: &crate::app::Session, _path: &str, _who: Vec) -> crate::out::Out { Err(Fail::new("bad_usage", "path rules need a hosted project").state("nothing changed")) } pub fn import(_app: &App, url: &str, _to: Option, _folder: Option) -> crate::out::Out { Err(Fail::new("failed", format!("importing {url} isn't ready yet")).state("nothing changed")) } pub fn publish(_app: &App, project: &str) -> crate::out::Out { Err(Fail::new("failed", format!("publishing to {project} isn't ready yet")).state("nothing changed")) } pub fn login(_app: &App, _host: Option, _token: Option) -> crate::out::Out { Err(Fail::new("failed", "login isn't ready yet").state("nothing changed")) } pub fn saver(_app: &App) -> crate::out::Out { Ok(crate::out::Report::new()) }