Compare commits
5 Commits
32b47d44ec
...
3ad5c4f706
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ad5c4f706 | |||
| 50c40c56db | |||
| bdf23a6e48 | |||
| b08e9616bf | |||
| 2a2bb0c2a3 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
auth/
|
||||
react-debug/public/photosync/
|
||||
|
||||
92
react-debug/src/App.js
vendored
92
react-debug/src/App.js
vendored
@ -1,6 +1,50 @@
|
||||
import React from 'react';
|
||||
|
||||
class App extends React.Component {
|
||||
class Album 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) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@ -18,29 +62,45 @@ class App extends React.Component {
|
||||
}
|
||||
render() {
|
||||
let {error, albums} = this.state;
|
||||
console.log(this.state);
|
||||
let content;
|
||||
if (error !== null) {
|
||||
content = <h2>Error: {JSON.stringify(error)}</h2>;
|
||||
return <h2>Error: {JSON.stringify(error)}</h2>;
|
||||
} else if (albums !== null) {
|
||||
console.log(albums);
|
||||
content = albums.map((a) => {
|
||||
let thumb = <img className="mr-3"/>;
|
||||
return albums.map((a) => {
|
||||
let img = <img src="https://via.placeholder.com/256x128" className="mr-3" alt="unset"/>;
|
||||
if (a.coverPhotoBaseUrl !== undefined) {
|
||||
thumb = <img src={ a.coverPhotoBaseUrl + "=w64-h64-c" } className="mr-3" alt={ a.title }/>;
|
||||
img = <img src={ a.coverPhotoBaseUrl + "=w256" } className="mr-3" alt={ a.title }/>;
|
||||
}
|
||||
return <div key={ a.id } className="media">
|
||||
<a href={ a.productUrl }>
|
||||
{thumb}
|
||||
|
||||
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>
|
||||
<div className="media-body">
|
||||
<h5 className="mt-0">{ a.title }</h5>
|
||||
{ a.mediaItemsCount } photos
|
||||
</div>
|
||||
</div>
|
||||
});
|
||||
} else {
|
||||
content = <h2>Loading...</h2>;
|
||||
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);
|
||||
let content;
|
||||
if (curAlbum) {
|
||||
content = <Album album={ curAlbum.slice(1) } />
|
||||
} else {
|
||||
content = <AlbumIndex />;
|
||||
}
|
||||
|
||||
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 media_items = SearchIter::new(
|
||||
&client,
|
||||
@ -148,7 +148,7 @@ fn search_media_items(client: photos::Client, album_id: String) -> Result<(), Bo
|
||||
}
|
||||
|
||||
fn sync_albums(
|
||||
client: photos::Client,
|
||||
client: &photos::Client,
|
||||
title_filter: Option<Regex>,
|
||||
output_dir: PathBuf,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
@ -157,8 +157,13 @@ fn sync_albums(
|
||||
let album_dir = output_dir.join(a.id.as_ref().expect("missing album id"));
|
||||
if !album_dir.exists() {
|
||||
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.
|
||||
let j = serde_json::to_string(&albums)?;
|
||||
@ -181,7 +186,7 @@ fn print_albums(albums: Vec<Album>) {
|
||||
}
|
||||
|
||||
fn list_albums(
|
||||
client: photos::Client,
|
||||
client: &photos::Client,
|
||||
title_filter: Option<Regex>,
|
||||
) -> Result<Vec<Album>, Box<dyn Error>> {
|
||||
Ok(client
|
||||
@ -215,13 +220,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = new_client(&opt.credentials, &opt.token_cache)?;
|
||||
match opt.cmd {
|
||||
Command::ListAlbums { title_filter } => {
|
||||
print_albums(list_albums(client, title_filter)?);
|
||||
print_albums(list_albums(&client, title_filter)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::SearchMediaItems { album_id } => search_media_items(client, album_id),
|
||||
Command::SearchMediaItems { album_id } => search_media_items(&client, album_id),
|
||||
Command::Sync {
|
||||
title_filter,
|
||||
output,
|
||||
} => sync_albums(client, title_filter, output),
|
||||
} => sync_albums(&client, title_filter, output),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user