Stub websever, don't store to API given filename (sometimes they have /)
This commit is contained in:
parent
93af9725df
commit
2dd5bb1d43
24
src/main.rs
24
src/main.rs
@ -3,6 +3,7 @@ use std::error::Error;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use google_api_auth;
|
||||
@ -32,6 +33,13 @@ enum Command {
|
||||
/// Directory to store sync.
|
||||
output: PathBuf,
|
||||
},
|
||||
Serve {
|
||||
/// Directory of data fetched by `sync`.
|
||||
root: PathBuf,
|
||||
/// HTTP address to listen for web requests.
|
||||
#[structopt(long = "addr", default_value = "0.0.0.0:0")]
|
||||
addr: SocketAddr,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
@ -179,6 +187,11 @@ fn sync_albums(
|
||||
title_filter: Option<Regex>,
|
||||
output_dir: PathBuf,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// Put images from all albums in common directory.
|
||||
let image_dir = output_dir.join("images");
|
||||
if !image_dir.exists() {
|
||||
fs::create_dir_all(&image_dir)?;
|
||||
}
|
||||
let albums = list_albums(client, title_filter)?;
|
||||
for a in &albums {
|
||||
let album_id = a.id.as_ref().expect("unset album id").to_string();
|
||||
@ -195,12 +208,7 @@ fn sync_albums(
|
||||
.filename
|
||||
.as_ref()
|
||||
.map_or("NO_FILENAME".to_string(), |s| s.to_string());
|
||||
// Put images from all albums in common directory.
|
||||
let image_path = output_dir.join("images").join(&mi_id);
|
||||
if !image_path.exists() {
|
||||
fs::create_dir_all(&image_path)?;
|
||||
}
|
||||
let image_path = image_path.join(&filename);
|
||||
let image_path = image_dir.join(mi_id);
|
||||
if image_path.exists() {
|
||||
info!(
|
||||
"Skipping already downloaded {} @ {}",
|
||||
@ -277,6 +285,9 @@ fn list_albums(
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
pub fn serve(addr: SocketAddr, root: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let opt = Opt::from_args();
|
||||
@ -300,5 +311,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
title_filter,
|
||||
output,
|
||||
} => sync_albums(&client, title_filter, output),
|
||||
Command::Serve { addr, root } => serve(addr, root),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user