Compare commits
No commits in common. "3ad5c4f7067c916423f568a1bf312a2a17101703" and "32b47d44ec83eb66188d07db31f33ff53fbae1b3" have entirely different histories.
3ad5c4f706
...
32b47d44ec
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
auth/
|
auth/
|
||||||
react-debug/public/photosync/
|
|
||||||
|
|||||||
102
react-debug/src/App.js
vendored
102
react-debug/src/App.js
vendored
@ -1,50 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
class Album extends React.Component {
|
class App extends React.Component {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
error: null,
|
|
||||||
album: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
let {album} = this.props;
|
|
||||||
fetch(process.env.PUBLIC_URL + `/photosync/${album}/album.json`)
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(
|
|
||||||
(result) => this.setState({album: result}),
|
|
||||||
(error) => this.setState({error}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
let {error, album} = this.state;
|
|
||||||
console.log(this.state);
|
|
||||||
if (error !== null) {
|
|
||||||
return <h2>Error: {JSON.stringify(error)}</h2>;
|
|
||||||
} 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 }
|
|
||||||
</a>
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return <h2>Loading...</h2>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AlbumIndex extends React.Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@ -62,45 +18,29 @@ class AlbumIndex extends React.Component {
|
|||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
let {error, albums} = this.state;
|
let {error, albums} = this.state;
|
||||||
if (error !== null) {
|
|
||||||
return <h2>Error: {JSON.stringify(error)}</h2>;
|
|
||||||
} else if (albums !== null) {
|
|
||||||
console.log(albums);
|
|
||||||
return albums.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.id }>
|
|
||||||
{ figure }
|
|
||||||
</a>
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return <h2>Loading...</h2>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class App extends React.Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
curAlbum: window.location.hash,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
let {curAlbum} = this.state;
|
|
||||||
console.log(this.state);
|
console.log(this.state);
|
||||||
let content;
|
let content;
|
||||||
if (curAlbum) {
|
if (error !== null) {
|
||||||
content = <Album album={ curAlbum.slice(1) } />
|
content = <h2>Error: {JSON.stringify(error)}</h2>;
|
||||||
|
} else if (albums !== null) {
|
||||||
|
console.log(albums);
|
||||||
|
content = albums.map((a) => {
|
||||||
|
let thumb = <img className="mr-3"/>;
|
||||||
|
if (a.coverPhotoBaseUrl !== undefined) {
|
||||||
|
thumb = <img src={ a.coverPhotoBaseUrl + "=w64-h64-c" } className="mr-3" alt={ a.title }/>;
|
||||||
|
}
|
||||||
|
return <div key={ a.id } className="media">
|
||||||
|
<a href={ a.productUrl }>
|
||||||
|
{thumb}
|
||||||
|
</a>
|
||||||
|
<div className="media-body">
|
||||||
|
<h5 className="mt-0">{ a.title }</h5>
|
||||||
|
{ a.mediaItemsCount } photos
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
content = <AlbumIndex />;
|
content = <h2>Loading...</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@ -123,7 +123,7 @@ impl<'a> Iterator for SearchIter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), Box<dyn Error>> {
|
fn search_media_items(client: photos::Client, album_id: String) -> Result<(), Box<dyn Error>> {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
let media_items = SearchIter::new(
|
let media_items = SearchIter::new(
|
||||||
&client,
|
&client,
|
||||||
@ -148,7 +148,7 @@ fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), B
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sync_albums(
|
fn sync_albums(
|
||||||
client: &photos::Client,
|
client: photos::Client,
|
||||||
title_filter: Option<Regex>,
|
title_filter: Option<Regex>,
|
||||||
output_dir: PathBuf,
|
output_dir: PathBuf,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
@ -157,13 +157,8 @@ fn sync_albums(
|
|||||||
let album_dir = output_dir.join(a.id.as_ref().expect("missing album id"));
|
let album_dir = output_dir.join(a.id.as_ref().expect("missing album id"));
|
||||||
if !album_dir.exists() {
|
if !album_dir.exists() {
|
||||||
info!("making album directory {}", album_dir.to_string_lossy());
|
info!("making album directory {}", album_dir.to_string_lossy());
|
||||||
fs::create_dir_all(&album_dir)?;
|
fs::create_dir_all(album_dir)?;
|
||||||
}
|
}
|
||||||
let j = serde_json::to_string(&albums)?;
|
|
||||||
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.
|
// Serialize it to a JSON string.
|
||||||
let j = serde_json::to_string(&albums)?;
|
let j = serde_json::to_string(&albums)?;
|
||||||
@ -186,7 +181,7 @@ fn print_albums(albums: Vec<Album>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn list_albums(
|
fn list_albums(
|
||||||
client: &photos::Client,
|
client: photos::Client,
|
||||||
title_filter: Option<Regex>,
|
title_filter: Option<Regex>,
|
||||||
) -> Result<Vec<Album>, Box<dyn Error>> {
|
) -> Result<Vec<Album>, Box<dyn Error>> {
|
||||||
Ok(client
|
Ok(client
|
||||||
@ -220,13 +215,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let client = new_client(&opt.credentials, &opt.token_cache)?;
|
let client = new_client(&opt.credentials, &opt.token_cache)?;
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
Command::ListAlbums { title_filter } => {
|
Command::ListAlbums { title_filter } => {
|
||||||
print_albums(list_albums(&client, title_filter)?);
|
print_albums(list_albums(client, title_filter)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Command::SearchMediaItems { album_id } => search_media_items(&client, album_id),
|
Command::SearchMediaItems { album_id } => search_media_items(client, album_id),
|
||||||
Command::Sync {
|
Command::Sync {
|
||||||
title_filter,
|
title_filter,
|
||||||
output,
|
output,
|
||||||
} => sync_albums(&client, title_filter, output),
|
} => sync_albums(client, title_filter, output),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user