Cleanup some more.

Get rid of lib.rs, and move main entry point to main.rs.
This commit is contained in:
Rasmus Kaj 2017-09-02 00:05:44 +02:00
parent ce1e9c6190
commit 16a1b75643
20 changed files with 79 additions and 88 deletions

View File

@ -8,10 +8,6 @@ build = "src/build.rs"
[build-dependencies] [build-dependencies]
ructe = { version = "^0.3.2", features = ["sass", "mime02"] } ructe = { version = "^0.3.2", features = ["sass", "mime02"] }
[[bin]]
name = "rphotosadm"
path = "src/rphotosadm.rs"
[dependencies] [dependencies]
nickel = "~0.10.0" nickel = "~0.10.0"
nickel-jwt-session = "~0.10.0" nickel-jwt-session = "~0.10.0"

View File

@ -5,7 +5,7 @@ use diesel::pg::PgConnection;
use diesel::prelude::*; use diesel::prelude::*;
use photosdir::PhotosDir; use photosdir::PhotosDir;
use rexif::{ExifData, ExifEntry, ExifTag, TagValue}; use rexif::{ExifData, ExifEntry, ExifTag, TagValue};
use rphotos::models::{Modification, Photo, Camera}; use models::{Modification, Photo, Camera};
use std::path::Path; use std::path::Path;
pub fn crawl(db: &PgConnection, photos: &PhotosDir, only_in: &Path) pub fn crawl(db: &PgConnection, photos: &PhotosDir, only_in: &Path)
@ -44,7 +44,7 @@ fn save_photo(db: &PgConnection,
}; };
if let Some((lat, long)) = find_position(&exif)? { if let Some((lat, long)) = find_position(&exif)? {
debug!("Position for {} is {} {}", file_path, lat, long); debug!("Position for {} is {} {}", file_path, lat, long);
use rphotos::schema::positions::dsl::*; use schema::positions::dsl::*;
if let Ok((pos, clat, clong)) = if let Ok((pos, clat, clong)) =
positions.filter(photo_id.eq(photo.id)) positions.filter(photo_id.eq(photo.id))
.select((id, latitude, longitude)) .select((id, latitude, longitude))
@ -59,7 +59,7 @@ fn save_photo(db: &PgConnection,
} }
} else { } else {
info!("Position for {} is {} {}", file_path, lat, long); info!("Position for {} is {} {}", file_path, lat, long);
use rphotos::models::NewPosition; use models::NewPosition;
insert(&NewPosition { insert(&NewPosition {
photo_id: photo.id, photo_id: photo.id,
latitude: (lat * 1e6) as i32, latitude: (lat * 1e6) as i32,

View File

@ -4,14 +4,14 @@ use diesel::prelude::*;
use diesel::result::Error as DieselError; use diesel::result::Error as DieselError;
use diesel::update; use diesel::update;
use photosdir::PhotosDir; use photosdir::PhotosDir;
use rphotos::models::{Modification, Photo}; use models::{Modification, Photo};
use std::io::prelude::*; use std::io::prelude::*;
pub fn one(db: &PgConnection, pub fn one(db: &PgConnection,
photodir: &PhotosDir, photodir: &PhotosDir,
tpath: &str) tpath: &str)
-> Result<(), Error> { -> Result<(), Error> {
use rphotos::schema::photos::dsl::*; use schema::photos::dsl::*;
match update(photos.filter(path.eq(&tpath))) match update(photos.filter(path.eq(&tpath)))
.set(is_public.eq(true)) .set(is_public.eq(true))
.get_result::<Photo>(db) { .get_result::<Photo>(db) {
@ -45,7 +45,7 @@ pub fn by_file_list<In: BufRead + Sized>(db: &PgConnection,
fn register_photo(db: &PgConnection, fn register_photo(db: &PgConnection,
tpath: &str) tpath: &str)
-> Result<Photo, DieselError> { -> Result<Photo, DieselError> {
use rphotos::schema::photos::dsl::{photos, is_public}; use schema::photos::dsl::{photos, is_public};
let photo = let photo =
match Photo::create_or_set_basics(&db, &tpath, None, 0, None)? { match Photo::create_or_set_basics(&db, &tpath, None, 0, None)? {
Modification::Created(photo) => photo, Modification::Created(photo) => photo,

View File

@ -3,7 +3,7 @@ use chrono::naive::NaiveDateTime;
use diesel; use diesel;
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::prelude::*; use diesel::prelude::*;
use rphotos::models::{Modification, Person, Photo, Place, Tag}; use models::{Modification, Person, Photo, Place, Tag};
use std::fs::File; use std::fs::File;
use std::path::Path; use std::path::Path;
use std::result; use std::result;
@ -123,9 +123,9 @@ pub fn photo_by_path(db: &PgConnection,
} }
fn tag_photo(db: &PgConnection, thephoto: &Photo, tagname: &str) -> Result<()> { fn tag_photo(db: &PgConnection, thephoto: &Photo, tagname: &str) -> Result<()> {
use rphotos::models::{NewPhotoTag, NewTag, PhotoTag}; use models::{NewPhotoTag, NewTag, PhotoTag};
let tag = { let tag = {
use rphotos::schema::tags::dsl::*; use schema::tags::dsl::*;
tags.filter(tag_name.eq(tagname)) tags.filter(tag_name.eq(tagname))
.first::<Tag>(db) .first::<Tag>(db)
.or_else(|_| { .or_else(|_| {
@ -138,7 +138,7 @@ fn tag_photo(db: &PgConnection, thephoto: &Photo, tagname: &str) -> Result<()> {
}) })
}?; }?;
debug!(" tag {:?}", tag); debug!(" tag {:?}", tag);
use rphotos::schema::photo_tags::dsl::*; use schema::photo_tags::dsl::*;
let q = photo_tags.filter(photo_id.eq(thephoto.id)) let q = photo_tags.filter(photo_id.eq(thephoto.id))
.filter(tag_id.eq(tag.id)); .filter(tag_id.eq(tag.id));
if let Ok(result) = q.first::<PhotoTag>(db) { if let Ok(result) = q.first::<PhotoTag>(db) {
@ -157,9 +157,9 @@ fn tag_photo(db: &PgConnection, thephoto: &Photo, tagname: &str) -> Result<()> {
} }
fn person_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> { fn person_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> {
use rphotos::models::{NewPerson, NewPhotoPerson, PhotoPerson}; use models::{NewPerson, NewPhotoPerson, PhotoPerson};
let person = { let person = {
use rphotos::schema::people::dsl::*; use schema::people::dsl::*;
people.filter(person_name.eq(name)) people.filter(person_name.eq(name))
.first::<Person>(db) .first::<Person>(db)
.or_else(|_| { .or_else(|_| {
@ -172,7 +172,7 @@ fn person_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> {
}) })
}?; }?;
debug!(" person {:?}", person); debug!(" person {:?}", person);
use rphotos::schema::photo_people::dsl::*; use schema::photo_people::dsl::*;
let q = photo_people.filter(photo_id.eq(photo.id)) let q = photo_people.filter(photo_id.eq(photo.id))
.filter(person_id.eq(person.id)); .filter(person_id.eq(person.id));
if let Ok(result) = q.first::<PhotoPerson>(db) { if let Ok(result) = q.first::<PhotoPerson>(db) {
@ -193,9 +193,9 @@ fn person_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> {
} }
fn place_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> { fn place_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> {
use rphotos::models::{NewPhotoPlace, NewPlace, PhotoPlace}; use models::{NewPhotoPlace, NewPlace, PhotoPlace};
let place = { let place = {
use rphotos::schema::places::dsl::*; use schema::places::dsl::*;
places.filter(place_name.eq(name)) places.filter(place_name.eq(name))
.first::<Place>(db) .first::<Place>(db)
.or_else(|_| { .or_else(|_| {
@ -208,7 +208,7 @@ fn place_photo(db: &PgConnection, photo: &Photo, name: &str) -> Result<()> {
}) })
}?; }?;
debug!(" place {:?}", place); debug!(" place {:?}", place);
use rphotos::schema::photo_places::dsl::*; use schema::photo_places::dsl::*;
photo_places.filter(photo_id.eq(photo.id)) photo_places.filter(photo_id.eq(photo.id))
.filter(place_id.eq(place.id)) .filter(place_id.eq(place.id))
.first::<PhotoPlace>(db) .first::<PhotoPlace>(db)
@ -238,7 +238,7 @@ fn grade_photo(db: &PgConnection, photo: &mut Photo, name: &str) -> Result<()> {
photo))) photo)))
} }
}); });
use rphotos::schema::photos::dsl::*; use schema::photos::dsl::*;
let n = diesel::update(photos.find(photo.id)) let n = diesel::update(photos.find(photo.id))
.set(grade.eq(photo.grade)) .set(grade.eq(photo.grade))
.execute(db) .execute(db)

View File

@ -4,10 +4,10 @@ use diesel::expression::dsl::{count_star, sql};
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::types::{BigInt, Double, Nullable, Text, Timestamp}; use diesel::types::{BigInt, Double, Nullable, Text, Timestamp};
use rphotos::schema::people::dsl::people; use schema::people::dsl::people;
use rphotos::schema::photos::dsl::photos; use schema::photos::dsl::photos;
use rphotos::schema::places::dsl::places; use schema::places::dsl::places;
use rphotos::schema::tags::dsl::tags; use schema::tags::dsl::tags;
sql_function!(date_part, sql_function!(date_part,
date_part_t, date_part_t,
@ -25,7 +25,7 @@ pub fn show_stats(db: &PgConnection) -> Result<(), Error> {
// Something like this should be possible, I guess? // Something like this should be possible, I guess?
// //
// use rphotos::schema::photos::dsl::date; // use schema::photos::dsl::date;
// let year = date_part("year", date).aliased("y"); // let year = date_part("year", date).aliased("y");
// println!("Count per year: {:?}", // println!("Count per year: {:?}",
// photos.select((year, count_star())) // photos.select((year, count_star()))

View File

@ -9,7 +9,7 @@ use rand::os::OsRng;
use std::iter::Iterator; use std::iter::Iterator;
pub fn list(db: &PgConnection) -> Result<(), Error> { pub fn list(db: &PgConnection) -> Result<(), Error> {
use rphotos::schema::users::dsl::*; use schema::users::dsl::*;
println!("Existing users: {:?}.", println!("Existing users: {:?}.",
users.select(username).load::<String>(db)?); users.select(username).load::<String>(db)?);
Ok(()) Ok(())
@ -18,7 +18,7 @@ pub fn list(db: &PgConnection) -> Result<(), Error> {
pub fn passwd(db: &PgConnection, uname: &str) -> Result<(), Error> { pub fn passwd(db: &PgConnection, uname: &str) -> Result<(), Error> {
let pword = random_password(14); let pword = random_password(14);
let hashword = make_password(&pword); let hashword = make_password(&pword);
use rphotos::schema::users::dsl::*; use schema::users::dsl::*;
match update(users.filter(username.eq(&uname))) match update(users.filter(username.eq(&uname)))
.set(password.eq(&hashword)) .set(password.eq(&hashword))
.execute(db)? { .execute(db)? {
@ -26,7 +26,7 @@ pub fn passwd(db: &PgConnection, uname: &str) -> Result<(), Error> {
println!("Updated password for {:?} to {:?}", uname, pword); println!("Updated password for {:?} to {:?}", uname, pword);
} }
0 => { 0 => {
use rphotos::models::NewUser; use models::NewUser;
insert(&NewUser { insert(&NewUser {
username: &uname, username: &uname,
password: &hashword, password: &hashword,

View File

@ -1,9 +0,0 @@
#![recursion_limit="128"]
extern crate chrono;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_codegen;
pub mod schema;
pub mod models;

View File

@ -1,9 +1,11 @@
extern crate rphotos; #![recursion_limit="128"]
extern crate brotli2; extern crate brotli2;
extern crate clap; extern crate clap;
extern crate chrono; extern crate chrono;
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
#[macro_use]
extern crate diesel_codegen;
extern crate djangohashers; extern crate djangohashers;
extern crate dotenv; extern crate dotenv;
extern crate env_logger; extern crate env_logger;
@ -30,11 +32,13 @@ extern crate xml;
mod adm; mod adm;
mod env; mod env;
mod memcachemiddleware; mod memcachemiddleware;
mod models;
mod nickel_diesel; mod nickel_diesel;
mod photosdir; mod photosdir;
mod photosdirmiddleware; mod photosdirmiddleware;
mod pidfiles; mod pidfiles;
mod requestloggermiddleware; mod requestloggermiddleware;
mod schema;
mod server; mod server;
use adm::{findphotos, makepublic, readkpa, users, storestatics}; use adm::{findphotos, makepublic, readkpa, users, storestatics};

View File

@ -1,6 +1,6 @@
use image::{self, FilterType, GenericImage, ImageError, ImageFormat}; use image::{self, FilterType, GenericImage, ImageError, ImageFormat};
use rexif::{self, ExifData}; use rexif::{self, ExifData};
use rphotos::models::Photo; use models::Photo;
use std::{fs, io}; use std::{fs, io};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View File

@ -21,7 +21,7 @@ use nickel_diesel::{DieselMiddleware, DieselRequestExtensions};
use nickel_jwt_session::{SessionMiddleware, SessionRequestExtensions, use nickel_jwt_session::{SessionMiddleware, SessionRequestExtensions,
SessionResponseExtensions}; SessionResponseExtensions};
use r2d2::NopErrorHandler; use r2d2::NopErrorHandler;
use rphotos::models::{Person, Photo, Place, Tag}; use models::{Person, Photo, Place, Tag};
use env::{dburl, env_or, jwt_key, photos_dir}; use env::{dburl, env_or, jwt_key, photos_dir};
@ -126,7 +126,7 @@ fn do_login<'mw>(req: &mut Request,
let next = sanitize_next(form_data.get("next")).map(String::from); let next = sanitize_next(form_data.get("next")).map(String::from);
if let (Some(user), Some(pw)) = (form_data.get("user"), if let (Some(user), Some(pw)) = (form_data.get("user"),
form_data.get("password")) { form_data.get("password")) {
use rphotos::schema::users::dsl::*; use schema::users::dsl::*;
if let Ok(hash) = users.filter(username.eq(user)) if let Ok(hash) = users.filter(username.eq(user))
.select(password) .select(password)
.first::<String>(c) { .first::<String>(c) {
@ -223,7 +223,7 @@ fn show_image<'mw>(req: &Request,
the_id: i32, the_id: i32,
size: SizeTag) size: SizeTag)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::photos; use schema::photos::dsl::photos;
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
if let Ok(tphoto) = photos.find(the_id).first::<Photo>(c) { if let Ok(tphoto) = photos.find(the_id).first::<Photo>(c) {
if req.authorized_user().is_some() || tphoto.is_public() { if req.authorized_user().is_some() || tphoto.is_public() {
@ -258,14 +258,14 @@ fn get_image_data(req: &Request,
fn tag_all<'mw>(req: &mut Request, fn tag_all<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::tags::dsl::{id, tag_name, tags}; use schema::tags::dsl::{id, tag_name, tags};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
let query = tags.into_boxed(); let query = tags.into_boxed();
let query = if req.authorized_user().is_some() { let query = if req.authorized_user().is_some() {
query query
} else { } else {
use rphotos::schema::photo_tags::dsl as tp; use schema::photo_tags::dsl as tp;
use rphotos::schema::photos::dsl as p; use schema::photos::dsl as p;
query.filter(id.eq_any(tp::photo_tags query.filter(id.eq_any(tp::photo_tags
.select(tp::tag_id) .select(tp::tag_id)
.filter(tp::photo_id .filter(tp::photo_id
@ -284,11 +284,11 @@ fn tag_one<'mw>(req: &mut Request,
res: Response<'mw>, res: Response<'mw>,
tslug: String) tslug: String)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::tags::dsl::{slug, tags}; use schema::tags::dsl::{slug, tags};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
if let Ok(tag) = tags.filter(slug.eq(tslug)).first::<Tag>(c) { if let Ok(tag) = tags.filter(slug.eq(tslug)).first::<Tag>(c) {
use rphotos::schema::photos::dsl::{date, grade, id}; use schema::photos::dsl::{date, grade, id};
use rphotos::schema::photo_tags::dsl::{photo_id, photo_tags, tag_id}; use schema::photo_tags::dsl::{photo_id, photo_tags, tag_id};
return res.ok(|o| { return res.ok(|o| {
templates::tag(o, templates::tag(o,
req, req,
@ -307,13 +307,13 @@ fn tag_one<'mw>(req: &mut Request,
fn place_all<'mw>(req: &mut Request, fn place_all<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::places::dsl::{id, place_name, places}; use schema::places::dsl::{id, place_name, places};
let query = places.into_boxed(); let query = places.into_boxed();
let query = if req.authorized_user().is_some() { let query = if req.authorized_user().is_some() {
query query
} else { } else {
use rphotos::schema::photo_places::dsl as pp; use schema::photo_places::dsl as pp;
use rphotos::schema::photos::dsl as p; use schema::photos::dsl as p;
query.filter(id.eq_any(pp::photo_places query.filter(id.eq_any(pp::photo_places
.select(pp::place_id) .select(pp::place_id)
.filter(pp::photo_id .filter(pp::photo_id
@ -345,11 +345,11 @@ fn place_one<'mw>(req: &mut Request,
res: Response<'mw>, res: Response<'mw>,
tslug: String) tslug: String)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::places::dsl::{places, slug}; use schema::places::dsl::{places, slug};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
if let Ok(place) = places.filter(slug.eq(tslug)).first::<Place>(c) { if let Ok(place) = places.filter(slug.eq(tslug)).first::<Place>(c) {
use rphotos::schema::photos::dsl::{date, grade, id}; use schema::photos::dsl::{date, grade, id};
use rphotos::schema::photo_places::dsl::{photo_id, photo_places, use schema::photo_places::dsl::{photo_id, photo_places,
place_id}; place_id};
return res.ok(|o| templates::place( return res.ok(|o| templates::place(
o, o,
@ -367,13 +367,13 @@ fn place_one<'mw>(req: &mut Request,
fn person_all<'mw>(req: &mut Request, fn person_all<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::people::dsl::{id, people, person_name}; use schema::people::dsl::{id, people, person_name};
let query = people.into_boxed(); let query = people.into_boxed();
let query = if req.authorized_user().is_some() { let query = if req.authorized_user().is_some() {
query query
} else { } else {
use rphotos::schema::photo_people::dsl as pp; use schema::photo_people::dsl as pp;
use rphotos::schema::photos::dsl as p; use schema::photos::dsl as p;
query.filter(id.eq_any(pp::photo_people query.filter(id.eq_any(pp::photo_people
.select(pp::person_id) .select(pp::person_id)
.filter(pp::photo_id .filter(pp::photo_id
@ -392,11 +392,11 @@ fn person_one<'mw>(req: &mut Request,
res: Response<'mw>, res: Response<'mw>,
tslug: String) tslug: String)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::people::dsl::{people, slug}; use schema::people::dsl::{people, slug};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
if let Ok(person) = people.filter(slug.eq(tslug)).first::<Person>(c) { if let Ok(person) = people.filter(slug.eq(tslug)).first::<Person>(c) {
use rphotos::schema::photos::dsl::{date, grade, id}; use schema::photos::dsl::{date, grade, id};
use rphotos::schema::photo_people::dsl::{person_id, photo_id, use schema::photo_people::dsl::{person_id, photo_id,
photo_people}; photo_people};
return res.ok(|o| templates::person( return res.ok(|o| templates::person(
o, o,
@ -415,7 +415,7 @@ fn photo_details<'mw>(req: &mut Request,
res: Response<'mw>, res: Response<'mw>,
id: i32) id: i32)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::photos; use schema::photos::dsl::photos;
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
if let Ok(tphoto) = photos.find(id).first::<Photo>(c) { if let Ok(tphoto) = photos.find(id).first::<Photo>(c) {
if req.authorized_user().is_some() || tphoto.is_public() { if req.authorized_user().is_some() || tphoto.is_public() {
@ -428,28 +428,28 @@ fn photo_details<'mw>(req: &mut Request,
Link::day(d.year(), d.month(), d.day())]) Link::day(d.year(), d.month(), d.day())])
.unwrap_or_else(|| vec![]), .unwrap_or_else(|| vec![]),
&{ &{
use rphotos::schema::people::dsl::{people, id}; use schema::people::dsl::{people, id};
use rphotos::schema::photo_people::dsl::{photo_people, photo_id, person_id}; use schema::photo_people::dsl::{photo_people, photo_id, person_id};
people.filter(id.eq_any(photo_people.select(person_id) people.filter(id.eq_any(photo_people.select(person_id)
.filter(photo_id.eq(tphoto.id)))) .filter(photo_id.eq(tphoto.id))))
.load(c).unwrap() .load(c).unwrap()
}, },
&{ &{
use rphotos::schema::places::dsl::{places, id}; use schema::places::dsl::{places, id};
use rphotos::schema::photo_places::dsl::{photo_places, photo_id, place_id}; use schema::photo_places::dsl::{photo_places, photo_id, place_id};
places.filter(id.eq_any(photo_places.select(place_id) places.filter(id.eq_any(photo_places.select(place_id)
.filter(photo_id.eq(tphoto.id)))) .filter(photo_id.eq(tphoto.id))))
.load(c).unwrap() .load(c).unwrap()
}, },
&{ &{
use rphotos::schema::tags::dsl::{tags, id}; use schema::tags::dsl::{tags, id};
use rphotos::schema::photo_tags::dsl::{photo_tags, photo_id, tag_id}; use schema::photo_tags::dsl::{photo_tags, photo_id, tag_id};
tags.filter(id.eq_any(photo_tags.select(tag_id) tags.filter(id.eq_any(photo_tags.select(tag_id)
.filter(photo_id.eq(tphoto.id)))) .filter(photo_id.eq(tphoto.id))))
.load(c).unwrap() .load(c).unwrap()
}, },
{ {
use rphotos::schema::positions::dsl::*; use schema::positions::dsl::*;
match positions.filter(photo_id.eq(tphoto.id)) match positions.filter(photo_id.eq(tphoto.id))
.select((latitude, longitude)) .select((latitude, longitude))
.first::<(i32, i32)>(c) { .first::<(i32, i32)>(c) {
@ -465,13 +465,13 @@ fn photo_details<'mw>(req: &mut Request,
} }
}, },
{ {
use rphotos::schema::attributions::dsl::*; use schema::attributions::dsl::*;
tphoto.attribution_id.map(|i| { tphoto.attribution_id.map(|i| {
attributions.find(i).select(name).first(c).unwrap() attributions.find(i).select(name).first(c).unwrap()
}) })
}, },
{ {
use rphotos::schema::cameras::dsl::*; use schema::cameras::dsl::*;
tphoto.camera_id.map(|i| { tphoto.camera_id.map(|i| {
cameras.find(i).first(c).unwrap() cameras.find(i).first(c).unwrap()
}) })

View File

@ -4,11 +4,11 @@ use chrono::naive::NaiveDate;
use diesel::expression::sql_literal::SqlLiteral; use diesel::expression::sql_literal::SqlLiteral;
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::prelude::*; use diesel::prelude::*;
use models::Photo;
use nickel::{MiddlewareResult, Request, Response}; use nickel::{MiddlewareResult, Request, Response};
use nickel_diesel::DieselRequestExtensions; use nickel_diesel::DieselRequestExtensions;
use nickel_jwt_session::SessionRequestExtensions; use nickel_jwt_session::SessionRequestExtensions;
use server::nickelext::MyResponse; use server::nickelext::MyResponse;
use rphotos::models::Photo;
use templates; use templates;
use time; use time;
@ -17,7 +17,7 @@ pub fn all_years<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::{date, grade}; use schema::photos::dsl::{date, grade};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
let groups: Vec<Group> = let groups: Vec<Group> =
@ -59,7 +59,7 @@ pub fn months_in_year<'mw>(req: &mut Request,
res: Response<'mw>, res: Response<'mw>,
year: i32) year: i32)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::{date, grade}; use schema::photos::dsl::{date, grade};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
let title: String = format!("Photos from {}", year); let title: String = format!("Photos from {}", year);
@ -109,7 +109,7 @@ pub fn days_in_month<'mw>(req: &mut Request,
year: i32, year: i32,
month: u32) month: u32)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::{date, grade}; use schema::photos::dsl::{date, grade};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
let lpath: Vec<Link> = vec![Link::year(year)]; let lpath: Vec<Link> = vec![Link::year(year)];
@ -155,7 +155,7 @@ pub fn days_in_month<'mw>(req: &mut Request,
pub fn all_null_date<'mw>(req: &mut Request, pub fn all_null_date<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::{date, path}; use schema::photos::dsl::{date, path};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
res.ok(|o| templates::index( res.ok(|o| templates::index(
@ -177,7 +177,7 @@ pub fn all_for_day<'mw>(req: &mut Request,
day: u32) day: u32)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0); let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0);
use rphotos::schema::photos::dsl::date; use schema::photos::dsl::date;
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
@ -247,7 +247,7 @@ pub fn part_for_day<'mw>(
part: usize, part: usize,
) -> MiddlewareResult<'mw> { ) -> MiddlewareResult<'mw> {
let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0); let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0);
use rphotos::schema::photos::dsl::date; use schema::photos::dsl::date;
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
@ -293,7 +293,7 @@ pub fn part_for_day<'mw>(
pub fn on_this_day<'mw>(req: &mut Request, pub fn on_this_day<'mw>(req: &mut Request,
res: Response<'mw>) res: Response<'mw>)
-> MiddlewareResult<'mw> { -> MiddlewareResult<'mw> {
use rphotos::schema::photos::dsl::{date, grade}; use schema::photos::dsl::{date, grade};
let c: &PgConnection = &req.db_conn(); let c: &PgConnection = &req.db_conn();
let (month, day) = { let (month, day) = {

View File

@ -1,7 +1,7 @@
@use ::{Coord, Link}; @use ::{Coord, Link};
@use nickel::Request; @use nickel::Request;
@use nickel_jwt_session::SessionRequestExtensions; @use nickel_jwt_session::SessionRequestExtensions;
@use rphotos::models::{Photo, Person, Place, Tag, Camera}; @use models::{Photo, Person, Place, Tag, Camera};
@use templates::page_base; @use templates::page_base;
@(req: &Request, lpath: &[Link], people: &[Person], places: &[Place], tags: &[Tag], position: Option<Coord>, attribution: Option<String>, camera: Option<Camera>, photo: Photo) @(req: &Request, lpath: &[Link], people: &[Person], places: &[Place], tags: &[Tag], position: Option<Coord>, attribution: Option<String>, camera: Option<Camera>, photo: Photo)

View File

@ -1,4 +1,4 @@
@use rphotos::models::Photo; @use models::Photo;
@(photo: &Photo) @(photo: &Photo)
<p class="item"><a href="/img/@photo.id"><img src="/img/@photo.id-s.jpg"></a></p> <p class="item"><a href="/img/@photo.id"><img src="/img/@photo.id-s.jpg"></a></p>

View File

@ -1,6 +1,6 @@
@use ::Link; @use ::Link;
@use nickel::Request; @use nickel::Request;
@use rphotos::models::Photo; @use models::Photo;
@use templates::{page_base, img_link}; @use templates::{page_base, img_link};
@(req: &Request, title: &str, lpath: &[Link], photos: &[Photo]) @(req: &Request, title: &str, lpath: &[Link], photos: &[Photo])

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::Person; @use models::Person;
@use templates::page_base; @use templates::page_base;
@(req: &Request, people: &[Person]) @(req: &Request, people: &[Person])

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::{Photo, Person}; @use models::{Photo, Person};
@use templates::{page_base, img_link}; @use templates::{page_base, img_link};
@(req: &Request, photos: &[Photo], person: Person) @(req: &Request, photos: &[Photo], person: Person)

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::{Photo, Place}; @use models::{Photo, Place};
@use templates::{page_base, img_link}; @use templates::{page_base, img_link};
@(req: &Request, photos: &[Photo], place: Place) @(req: &Request, photos: &[Photo], place: Place)

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::Place; @use models::Place;
@use templates::page_base; @use templates::page_base;
@(req: &Request, places: &[Place]) @(req: &Request, places: &[Place])

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::{Photo, Tag}; @use models::{Photo, Tag};
@use templates::{page_base, img_link}; @use templates::{page_base, img_link};
@(req: &Request, photos: &[Photo], tag: Tag) @(req: &Request, photos: &[Photo], tag: Tag)

View File

@ -1,5 +1,5 @@
@use nickel::Request; @use nickel::Request;
@use rphotos::models::Tag; @use models::Tag;
@use templates::page_base; @use templates::page_base;
@(req: &Request, tags: &[Tag]) @(req: &Request, tags: &[Tag])