Write out images in per-album json.
This commit is contained in:
parent
cced612139
commit
df3d29ce7c
@ -36,3 +36,7 @@
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.figure {
|
||||
width: 285px;
|
||||
}
|
||||
|
||||
22
react-debug/src/App.js
vendored
22
react-debug/src/App.js
vendored
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import './App.css';
|
||||
|
||||
class Album extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -25,18 +27,16 @@ class Album extends React.Component {
|
||||
} else if (album !== null) {
|
||||
console.log(album);
|
||||
return album.map((a) => {
|
||||
let img = <img src="https://via.placeholder.com/256x128" className="mr-3" alt="unset"/>;
|
||||
if (a.coverPhotoBaseUrl !== undefined) {
|
||||
img = <img src={ a.coverPhotoBaseUrl + "=w256" } className="mr-3" alt={ a.title }/>;
|
||||
}
|
||||
|
||||
let figure = <figure key={ a.id } className="figure">
|
||||
{img}
|
||||
<figcaption className="figure-caption">{ a.title || "No title" } - { a.mediaItemsCount || 0 } photos </figcaption>
|
||||
</figure>;
|
||||
return <a key={ a.id } href={ a.productUrl }>
|
||||
{ figure }
|
||||
// TODO(wathiede): use coverPhotoMediaItemId and fetch from a
|
||||
// locally cached image.
|
||||
return <figure key={ a.id } className="figure">
|
||||
<img src={ a.baseUrl + "=w256-h256-c" } className="mr-3" alt={ a.filename }/>
|
||||
<figcaption className="figure-caption">
|
||||
<a key={ a.id } href={ a.productUrl }>
|
||||
<p className="text-truncate">{ a.filename}</p>
|
||||
</a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
});
|
||||
} else {
|
||||
return <h2>Loading...</h2>;
|
||||
|
||||
43
src/main.rs
43
src/main.rs
@ -123,8 +123,21 @@ impl<'a> Iterator for SearchIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), Box<dyn Error>> {
|
||||
let mut total = 0;
|
||||
fn print_media_items(media_items: Vec<MediaItem>) {
|
||||
for mi in &media_items {
|
||||
println!(
|
||||
"{} {}",
|
||||
mi.id.as_ref().unwrap_or(&"NO ID".to_string()),
|
||||
mi.filename.as_ref().unwrap_or(&"NO FILENAME".to_string())
|
||||
);
|
||||
}
|
||||
println!("({}) items total", media_items.len());
|
||||
}
|
||||
|
||||
fn search_media_items(
|
||||
client: &photos::Client,
|
||||
album_id: String,
|
||||
) -> Result<Vec<MediaItem>, Box<dyn Error>> {
|
||||
let media_items = SearchIter::new(
|
||||
&client,
|
||||
SearchMediaItemsRequest {
|
||||
@ -133,18 +146,10 @@ fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), B
|
||||
page_size: Some(100),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
for mi in media_items {
|
||||
let mi = mi?;
|
||||
total += 1;
|
||||
println!(
|
||||
"{} {}",
|
||||
mi.id.unwrap_or("NO ID".to_string()),
|
||||
mi.filename.unwrap_or("NO FILENAME".to_string())
|
||||
);
|
||||
}
|
||||
println!("({}) items total", total);
|
||||
Ok(())
|
||||
)
|
||||
.filter_map(|mi| mi.ok())
|
||||
.collect();
|
||||
Ok(media_items)
|
||||
}
|
||||
|
||||
fn sync_albums(
|
||||
@ -159,11 +164,12 @@ fn sync_albums(
|
||||
info!("making album directory {}", album_dir.to_string_lossy());
|
||||
fs::create_dir_all(&album_dir)?;
|
||||
}
|
||||
let j = serde_json::to_string(&albums)?;
|
||||
|
||||
let album = search_media_items(client, a.id.as_ref().expect("unset album id").to_string())?;
|
||||
let j = serde_json::to_string(&album)?;
|
||||
let path = album_dir.join("album.json");
|
||||
info!("saving {}", path.to_string_lossy());
|
||||
fs::write(path, j)?;
|
||||
search_media_items(client, a.id.as_ref().expect("unset album id").to_string());
|
||||
}
|
||||
// Serialize it to a JSON string.
|
||||
let j = serde_json::to_string(&albums)?;
|
||||
@ -223,7 +229,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
print_albums(list_albums(&client, title_filter)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::SearchMediaItems { album_id } => search_media_items(&client, album_id),
|
||||
Command::SearchMediaItems { album_id } => {
|
||||
print_media_items(search_media_items(&client, album_id)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::Sync {
|
||||
title_filter,
|
||||
output,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user