Merge server and adm to single binary.
This commit is contained in:
parent
97076336a6
commit
8131f5e5ec
@ -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 = "rphotoserver"
|
|
||||||
path = "src/main.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rphotosadm"
|
name = "rphotosadm"
|
||||||
path = "src/rphotosadm.rs"
|
path = "src/rphotosadm.rs"
|
||||||
|
@ -4,6 +4,7 @@ use flate2::{Compression, FlateWriteExt};
|
|||||||
use std::fs::{File, create_dir_all};
|
use std::fs::{File, create_dir_all};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use templates::statics::STATICS;
|
||||||
|
|
||||||
pub fn to_dir(dir: &str) -> Result<(), Error> {
|
pub fn to_dir(dir: &str) -> Result<(), Error> {
|
||||||
let dir: &Path = dir.as_ref();
|
let dir: &Path = dir.as_ref();
|
||||||
@ -22,5 +23,3 @@ pub fn to_dir(dir: &str) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/templates/statics.rs"));
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//! Just fooling around with different ways to count images per year.
|
|
||||||
extern crate rphotos;
|
extern crate rphotos;
|
||||||
extern crate brotli2;
|
extern crate brotli2;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
@ -9,8 +8,20 @@ extern crate djangohashers;
|
|||||||
extern crate dotenv;
|
extern crate dotenv;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate flate2;
|
extern crate flate2;
|
||||||
|
extern crate hyper;
|
||||||
|
extern crate libc;
|
||||||
|
extern crate memcached;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate nickel;
|
||||||
|
extern crate nickel_jwt_session;
|
||||||
|
extern crate plugin;
|
||||||
|
extern crate r2d2;
|
||||||
|
extern crate r2d2_diesel;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
extern crate regex;
|
||||||
extern crate rexif;
|
extern crate rexif;
|
||||||
|
extern crate time;
|
||||||
|
extern crate typemap;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
@ -18,7 +29,13 @@ extern crate xml;
|
|||||||
|
|
||||||
mod adm;
|
mod adm;
|
||||||
mod env;
|
mod env;
|
||||||
|
mod memcachemiddleware;
|
||||||
|
mod nickel_diesel;
|
||||||
mod photosdir;
|
mod photosdir;
|
||||||
|
mod photosdirmiddleware;
|
||||||
|
mod pidfiles;
|
||||||
|
mod requestloggermiddleware;
|
||||||
|
mod server;
|
||||||
|
|
||||||
use adm::{findphotos, makepublic, readkpa, users, storestatics};
|
use adm::{findphotos, makepublic, readkpa, users, storestatics};
|
||||||
use adm::result::Error;
|
use adm::result::Error;
|
||||||
@ -34,6 +51,8 @@ use std::io::{self, BufReader};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
|
pub use server::{Coord, Group, Link};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init().unwrap();
|
env_logger::init().unwrap();
|
||||||
@ -74,6 +93,18 @@ fn main() {
|
|||||||
.arg(Arg::with_name("DIR")
|
.arg(Arg::with_name("DIR")
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Directory to store the files in")))
|
.help("Directory to store the files in")))
|
||||||
|
.subcommand(SubCommand::with_name("runserver")
|
||||||
|
.about("RPhotos web server")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.arg(Arg::with_name("PIDFILE")
|
||||||
|
.long("pidfile")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Write (and read, if --replace) a pid file with the \
|
||||||
|
name given as <PIDFILE>."))
|
||||||
|
.arg(Arg::with_name("REPLACE")
|
||||||
|
.long("replace")
|
||||||
|
.help("Kill old server (identified by pid file) \
|
||||||
|
before running")))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match run(args) {
|
match run(args) {
|
||||||
@ -136,6 +167,9 @@ fn run(args: ArgMatches) -> Result<(), Error> {
|
|||||||
("storestatics", Some(args)) => {
|
("storestatics", Some(args)) => {
|
||||||
storestatics::to_dir(args.value_of("DIR").unwrap())
|
storestatics::to_dir(args.value_of("DIR").unwrap())
|
||||||
}
|
}
|
||||||
|
("runserver", Some(args)) => {
|
||||||
|
server::run(args)
|
||||||
|
}
|
||||||
_ => Ok(println!("No subcommand given.\n\n{}", args.usage())),
|
_ => Ok(println!("No subcommand given.\n\n{}", args.usage())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,3 +177,5 @@ fn run(args: ArgMatches) -> Result<(), Error> {
|
|||||||
fn get_db() -> Result<PgConnection, ConnectionError> {
|
fn get_db() -> Result<PgConnection, ConnectionError> {
|
||||||
PgConnection::establish(&dburl())
|
PgConnection::establish(&dburl())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||||
|
@ -1,33 +1,17 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nickel;
|
mod nickelext;
|
||||||
#[macro_use]
|
mod views_by_date;
|
||||||
extern crate log;
|
|
||||||
extern crate djangohashers;
|
|
||||||
extern crate env_logger;
|
|
||||||
extern crate nickel_jwt_session;
|
|
||||||
extern crate typemap;
|
|
||||||
extern crate plugin;
|
|
||||||
extern crate image;
|
|
||||||
extern crate hyper;
|
|
||||||
extern crate time;
|
|
||||||
extern crate chrono;
|
|
||||||
extern crate clap;
|
|
||||||
extern crate libc;
|
|
||||||
extern crate rexif;
|
|
||||||
extern crate rphotos;
|
|
||||||
extern crate r2d2;
|
|
||||||
extern crate diesel;
|
|
||||||
extern crate r2d2_diesel;
|
|
||||||
extern crate dotenv;
|
|
||||||
extern crate memcached;
|
|
||||||
extern crate regex;
|
|
||||||
|
|
||||||
|
use adm::result::Error;
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use clap::{App, Arg};
|
use clap::ArgMatches;
|
||||||
use diesel::pg::PgConnection;
|
use diesel::pg::PgConnection;
|
||||||
|
use diesel;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use dotenv::dotenv;
|
use djangohashers;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
|
use image;
|
||||||
|
use memcachemiddleware::MemcacheMiddleware;
|
||||||
use nickel::{Action, Continue, FormBody, Halt, HttpRouter, MediaType,
|
use nickel::{Action, Continue, FormBody, Halt, HttpRouter, MediaType,
|
||||||
MiddlewareResult, Nickel, NickelError, QueryString, Request,
|
MiddlewareResult, Nickel, NickelError, QueryString, Request,
|
||||||
Response};
|
Response};
|
||||||
@ -39,63 +23,36 @@ use nickel_jwt_session::{SessionMiddleware, SessionRequestExtensions,
|
|||||||
use r2d2::NopErrorHandler;
|
use r2d2::NopErrorHandler;
|
||||||
use rphotos::models::{Person, Photo, Place, Tag};
|
use rphotos::models::{Person, Photo, Place, Tag};
|
||||||
|
|
||||||
mod env;
|
|
||||||
use env::{dburl, env_or, jwt_key, photos_dir};
|
use env::{dburl, env_or, jwt_key, photos_dir};
|
||||||
|
|
||||||
mod nickel_diesel;
|
|
||||||
|
|
||||||
mod photosdir;
|
|
||||||
|
|
||||||
mod requestloggermiddleware;
|
|
||||||
use requestloggermiddleware::RequestLoggerMiddleware;
|
use requestloggermiddleware::RequestLoggerMiddleware;
|
||||||
|
|
||||||
mod photosdirmiddleware;
|
|
||||||
use photosdirmiddleware::{PhotosDirMiddleware, PhotosDirRequestExtensions};
|
use photosdirmiddleware::{PhotosDirMiddleware, PhotosDirRequestExtensions};
|
||||||
|
|
||||||
mod memcachemiddleware;
|
|
||||||
use memcachemiddleware::*;
|
use memcachemiddleware::*;
|
||||||
|
|
||||||
mod pidfiles;
|
|
||||||
use pidfiles::handle_pid_file;
|
use pidfiles::handle_pid_file;
|
||||||
|
use templates;
|
||||||
|
|
||||||
#[macro_use]
|
use self::nickelext::{FromSlug, MyResponse, far_expires};
|
||||||
mod nickelext;
|
|
||||||
use nickelext::{FromSlug, MyResponse, far_expires};
|
|
||||||
|
|
||||||
mod views_by_date;
|
use self::views_by_date::*;
|
||||||
use views_by_date::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Group {
|
pub struct Group {
|
||||||
title: String,
|
pub title: String,
|
||||||
url: String,
|
pub url: String,
|
||||||
count: i64,
|
pub count: i64,
|
||||||
photo: Photo,
|
pub photo: Photo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Coord {
|
pub struct Coord {
|
||||||
x: f64,
|
pub x: f64,
|
||||||
y: f64,
|
pub y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
pub fn run(args: &ArgMatches) -> Result<(), Error> {
|
||||||
dotenv().ok();
|
|
||||||
env_logger::init().unwrap();
|
|
||||||
info!("Initalized logger");
|
|
||||||
let args = App::new("rphotoserver")
|
|
||||||
.about("RPhotos web server")
|
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
|
||||||
.arg(Arg::with_name("PIDFILE")
|
|
||||||
.long("pidfile")
|
|
||||||
.takes_value(true)
|
|
||||||
.help("Write (and read, if --replace) a pid file with the name \
|
|
||||||
given as <PIDFILE>."))
|
|
||||||
.arg(Arg::with_name("REPLACE")
|
|
||||||
.long("replace")
|
|
||||||
.help("Kill old server (identified by pid file) before running"))
|
|
||||||
.get_matches();
|
|
||||||
|
|
||||||
if let Some(pidfile) = args.value_of("PIDFILE") {
|
if let Some(pidfile) = args.value_of("PIDFILE") {
|
||||||
handle_pid_file(pidfile, args.is_present("REPLACE"))
|
handle_pid_file(pidfile, args.is_present("REPLACE"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -136,7 +93,8 @@ fn main() {
|
|||||||
server.handle_error(custom_handler);
|
server.handle_error(custom_handler);
|
||||||
|
|
||||||
server.listen(&*env_or("RPHOTOS_LISTEN", "127.0.0.1:6767"))
|
server.listen(&*env_or("RPHOTOS_LISTEN", "127.0.0.1:6767"))
|
||||||
.expect("listen");
|
.map_err(|e| Error::Other(format!("listen: {}", e)))?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -551,5 +509,3 @@ impl Link {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
|
@ -7,7 +7,7 @@ use diesel::prelude::*;
|
|||||||
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 nickelext::MyResponse;
|
use server::nickelext::MyResponse;
|
||||||
use rphotos::models::Photo;
|
use rphotos::models::Photo;
|
||||||
use templates;
|
use templates;
|
||||||
use time;
|
use time;
|
Loading…
Reference in New Issue
Block a user