Add a command to make images public by tag.
This commit is contained in:
parent
3d8530c0ec
commit
19e714970b
@ -23,22 +23,50 @@ pub struct Makepublic {
|
||||
/// File listing image paths to make public
|
||||
#[structopt(long, short, group = "spec")]
|
||||
list: Option<String>,
|
||||
/// Make all images with matching tag public.
|
||||
///
|
||||
/// The tag is specified by its slug.
|
||||
#[structopt(long, short, group = "spec")]
|
||||
tag: Option<String>,
|
||||
}
|
||||
|
||||
impl Makepublic {
|
||||
pub fn run(&self) -> Result<(), Error> {
|
||||
let db = self.db.connect()?;
|
||||
match (self.list.as_ref().map(AsRef::as_ref), &self.image) {
|
||||
(Some("-"), None) => {
|
||||
match (
|
||||
self.list.as_ref().map(AsRef::as_ref),
|
||||
&self.tag,
|
||||
&self.image,
|
||||
) {
|
||||
(Some("-"), None, None) => {
|
||||
let list = io::stdin();
|
||||
by_file_list(&db, list.lock())?;
|
||||
Ok(())
|
||||
}
|
||||
(Some(list), None) => {
|
||||
(Some(list), None, None) => {
|
||||
let list = BufReader::new(File::open(list)?);
|
||||
by_file_list(&db, list)
|
||||
}
|
||||
(None, Some(image)) => one(&db, image),
|
||||
(None, Some(tag), None) => {
|
||||
use crate::schema::photo_tags::dsl as pt;
|
||||
use crate::schema::photos::dsl as p;
|
||||
use crate::schema::tags::dsl as t;
|
||||
let n = update(
|
||||
p::photos.filter(
|
||||
p::id.eq_any(
|
||||
pt::photo_tags
|
||||
.select(pt::photo_id)
|
||||
.left_join(t::tags)
|
||||
.filter(t::slug.eq(tag)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.set(p::is_public.eq(true))
|
||||
.execute(&db)?;
|
||||
println!("Made {} images public.", n);
|
||||
Ok(())
|
||||
}
|
||||
(None, None, Some(image)) => one(&db, image),
|
||||
_ => Err(Error::Other("bad command".to_string())),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user