2020-06-06 21:02:26 +00:00
|
|
|
use actix_form_data::{Field, Form, Value};
|
|
|
|
use actix_web::{
|
2020-06-07 15:59:58 +00:00
|
|
|
client::Client,
|
2020-06-06 21:02:26 +00:00
|
|
|
guard,
|
2020-06-06 21:41:17 +00:00
|
|
|
http::header::{CacheControl, CacheDirective},
|
2020-06-07 02:14:31 +00:00
|
|
|
middleware::{Compress, Logger},
|
2020-06-06 21:41:17 +00:00
|
|
|
web, App, HttpResponse, HttpServer,
|
2020-06-06 21:02:26 +00:00
|
|
|
};
|
2020-06-06 21:41:17 +00:00
|
|
|
use futures::stream::{Stream, TryStreamExt};
|
2020-06-15 02:41:45 +00:00
|
|
|
use image::{ImageFormat, ImageOutputFormat};
|
2020-06-14 15:07:31 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2020-06-07 19:12:19 +00:00
|
|
|
use std::{collections::HashSet, path::PathBuf};
|
2020-06-07 00:54:06 +00:00
|
|
|
use structopt::StructOpt;
|
2020-06-14 15:07:31 +00:00
|
|
|
use tracing::{debug, error, info, instrument, Span};
|
2020-06-14 02:28:06 +00:00
|
|
|
use tracing_subscriber::EnvFilter;
|
2020-06-06 21:41:17 +00:00
|
|
|
|
2020-06-07 00:54:06 +00:00
|
|
|
mod config;
|
2020-06-06 21:41:17 +00:00
|
|
|
mod error;
|
2020-06-14 02:28:06 +00:00
|
|
|
mod middleware;
|
2020-06-07 17:51:45 +00:00
|
|
|
mod processor;
|
2020-06-06 21:41:17 +00:00
|
|
|
mod upload_manager;
|
2020-06-11 16:46:00 +00:00
|
|
|
mod validate;
|
2020-06-06 21:41:17 +00:00
|
|
|
|
2020-06-14 02:28:06 +00:00
|
|
|
use self::{
|
2020-06-14 15:07:31 +00:00
|
|
|
config::Config, error::UploadError, middleware::Tracing, upload_manager::UploadManager,
|
2020-06-14 02:28:06 +00:00
|
|
|
};
|
2020-06-06 21:02:26 +00:00
|
|
|
|
|
|
|
const MEGABYTES: usize = 1024 * 1024;
|
|
|
|
const HOURS: u32 = 60 * 60;
|
|
|
|
|
2020-06-14 15:07:31 +00:00
|
|
|
static CONFIG: Lazy<Config> = Lazy::new(|| Config::from_args());
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Try writing to a file
|
2020-06-14 15:07:31 +00:00
|
|
|
#[instrument(skip(bytes))]
|
2020-06-06 21:41:17 +00:00
|
|
|
async fn safe_save_file(path: PathBuf, bytes: bytes::Bytes) -> Result<(), UploadError> {
|
|
|
|
if let Some(path) = path.parent() {
|
|
|
|
// create the directory for the file
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("Creating directory {:?}", path);
|
2020-06-06 21:41:17 +00:00
|
|
|
actix_fs::create_dir_all(path.to_owned()).await?;
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Only write the file if it doesn't already exist
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("Checking if {:?} already exists", path);
|
2020-06-06 21:41:17 +00:00
|
|
|
if let Err(e) = actix_fs::metadata(path.clone()).await {
|
|
|
|
if e.kind() != Some(std::io::ErrorKind::NotFound) {
|
2020-06-06 21:02:26 +00:00
|
|
|
return Err(e.into());
|
|
|
|
}
|
2020-06-06 21:41:17 +00:00
|
|
|
} else {
|
|
|
|
return Ok(());
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Open the file for writing
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("Creating {:?}", path);
|
2020-06-06 21:41:17 +00:00
|
|
|
let file = actix_fs::file::create(path.clone()).await?;
|
2020-06-06 21:02:26 +00:00
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// try writing
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("Writing to {:?}", path);
|
2020-06-06 21:41:17 +00:00
|
|
|
if let Err(e) = actix_fs::file::write(file, bytes).await {
|
2020-06-14 15:07:31 +00:00
|
|
|
error!("Error writing {:?}, {}", path, e);
|
2020-06-06 21:41:17 +00:00
|
|
|
// remove file if writing failed before completion
|
|
|
|
actix_fs::remove_file(path).await?;
|
|
|
|
return Err(e.into());
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("{:?} written", path);
|
2020-06-06 21:02:26 +00:00
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
Ok(())
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn to_ext(mime: mime::Mime) -> &'static str {
|
|
|
|
if mime == mime::IMAGE_PNG {
|
|
|
|
".png"
|
|
|
|
} else if mime == mime::IMAGE_JPEG {
|
|
|
|
".jpg"
|
|
|
|
} else if mime == mime::IMAGE_GIF {
|
|
|
|
".gif"
|
|
|
|
} else {
|
|
|
|
".bmp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_ext(ext: std::ffi::OsString) -> mime::Mime {
|
|
|
|
match ext.to_str() {
|
|
|
|
Some("png") => mime::IMAGE_PNG,
|
|
|
|
Some("jpg") => mime::IMAGE_JPEG,
|
|
|
|
Some("gif") => mime::IMAGE_GIF,
|
|
|
|
_ => mime::IMAGE_BMP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
/// Handle responding to succesful uploads
|
2020-06-14 18:56:42 +00:00
|
|
|
#[instrument(skip(value, manager))]
|
2020-06-07 00:29:15 +00:00
|
|
|
async fn upload(
|
|
|
|
value: Value,
|
|
|
|
manager: web::Data<UploadManager>,
|
|
|
|
) -> Result<HttpResponse, UploadError> {
|
2020-06-06 21:02:26 +00:00
|
|
|
let images = value
|
|
|
|
.map()
|
|
|
|
.and_then(|mut m| m.remove("images"))
|
|
|
|
.and_then(|images| images.array())
|
|
|
|
.ok_or(UploadError::NoFiles)?;
|
|
|
|
|
|
|
|
let mut files = Vec::new();
|
|
|
|
for image in images.into_iter().filter_map(|i| i.file()) {
|
|
|
|
if let Some(saved_as) = image
|
|
|
|
.saved_as
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|s| s.file_name())
|
|
|
|
.and_then(|s| s.to_str())
|
|
|
|
{
|
|
|
|
info!("Uploaded {} as {:?}", image.filename, saved_as);
|
2020-06-07 00:29:15 +00:00
|
|
|
let delete_token = manager.delete_token(saved_as.to_owned()).await?;
|
|
|
|
files.push(serde_json::json!({
|
|
|
|
"file": saved_as,
|
2020-06-07 15:59:58 +00:00
|
|
|
"delete_token": delete_token
|
2020-06-07 00:29:15 +00:00
|
|
|
}));
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 15:59:58 +00:00
|
|
|
Ok(HttpResponse::Created().json(serde_json::json!({
|
|
|
|
"msg": "ok",
|
|
|
|
"files": files
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// download an image from a URL
|
2020-06-14 15:07:31 +00:00
|
|
|
#[instrument(skip(client, manager))]
|
2020-06-07 15:59:58 +00:00
|
|
|
async fn download(
|
|
|
|
client: web::Data<Client>,
|
|
|
|
manager: web::Data<UploadManager>,
|
|
|
|
query: web::Query<UrlQuery>,
|
|
|
|
) -> Result<HttpResponse, UploadError> {
|
|
|
|
let mut res = client.get(&query.url).send().await?;
|
|
|
|
|
|
|
|
if !res.status().is_success() {
|
|
|
|
return Err(UploadError::Download(res.status()));
|
|
|
|
}
|
|
|
|
|
2020-06-14 15:07:31 +00:00
|
|
|
let fut = res.body().limit(CONFIG.max_file_size() * MEGABYTES);
|
2020-06-07 15:59:58 +00:00
|
|
|
|
|
|
|
let stream = Box::pin(futures::stream::once(fut));
|
|
|
|
|
2020-06-14 15:07:31 +00:00
|
|
|
let alias = manager.upload(stream).await?;
|
2020-06-07 15:59:58 +00:00
|
|
|
let delete_token = manager.delete_token(alias.clone()).await?;
|
|
|
|
|
|
|
|
Ok(HttpResponse::Created().json(serde_json::json!({
|
|
|
|
"msg": "ok",
|
|
|
|
"files": [{
|
|
|
|
"file": alias,
|
|
|
|
"delete_token": delete_token
|
|
|
|
}]
|
|
|
|
})))
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 02:41:45 +00:00
|
|
|
/// Delete aliases and files
|
2020-06-14 15:07:31 +00:00
|
|
|
#[instrument(skip(manager))]
|
2020-06-07 00:29:15 +00:00
|
|
|
async fn delete(
|
|
|
|
manager: web::Data<UploadManager>,
|
|
|
|
path_entries: web::Path<(String, String)>,
|
|
|
|
) -> Result<HttpResponse, UploadError> {
|
|
|
|
let (alias, token) = path_entries.into_inner();
|
|
|
|
|
|
|
|
manager.delete(token, alias).await?;
|
|
|
|
|
|
|
|
Ok(HttpResponse::NoContent().finish())
|
|
|
|
}
|
|
|
|
|
2020-06-15 02:41:45 +00:00
|
|
|
fn convert_format(format: ImageFormat) -> Result<ImageOutputFormat, UploadError> {
|
|
|
|
match format {
|
|
|
|
ImageFormat::Jpeg => Ok(ImageOutputFormat::Jpeg(100)),
|
|
|
|
ImageFormat::Png => Ok(ImageOutputFormat::Png),
|
|
|
|
ImageFormat::Gif => Ok(ImageOutputFormat::Gif),
|
|
|
|
ImageFormat::Bmp => Ok(ImageOutputFormat::Bmp),
|
|
|
|
_ => Err(UploadError::UnsupportedFormat),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:51:45 +00:00
|
|
|
/// Serve files
|
2020-06-14 18:56:42 +00:00
|
|
|
#[instrument(skip(manager, whitelist))]
|
2020-06-06 21:02:26 +00:00
|
|
|
async fn serve(
|
2020-06-07 17:51:45 +00:00
|
|
|
segments: web::Path<String>,
|
2020-06-07 19:12:19 +00:00
|
|
|
manager: web::Data<UploadManager>,
|
|
|
|
whitelist: web::Data<Option<HashSet<String>>>,
|
2020-06-06 21:02:26 +00:00
|
|
|
) -> Result<HttpResponse, UploadError> {
|
2020-06-07 17:51:45 +00:00
|
|
|
let mut segments: Vec<String> = segments
|
|
|
|
.into_inner()
|
|
|
|
.split('/')
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
.collect();
|
|
|
|
let alias = segments.pop().ok_or(UploadError::MissingFilename)?;
|
2020-06-06 21:41:17 +00:00
|
|
|
|
2020-06-14 02:28:06 +00:00
|
|
|
debug!("Building chain");
|
2020-06-07 19:12:19 +00:00
|
|
|
let chain = self::processor::build_chain(&segments, whitelist.as_ref().as_ref());
|
2020-06-14 02:28:06 +00:00
|
|
|
debug!("Chain built");
|
2020-06-06 21:02:26 +00:00
|
|
|
|
2020-06-06 22:43:33 +00:00
|
|
|
let name = manager.from_alias(alias).await?;
|
2020-06-07 17:51:45 +00:00
|
|
|
let base = manager.image_dir();
|
|
|
|
let path = self::processor::build_path(base, &chain, name.clone());
|
2020-06-06 21:41:17 +00:00
|
|
|
|
2020-06-06 21:02:26 +00:00
|
|
|
let ext = path
|
|
|
|
.extension()
|
|
|
|
.ok_or(UploadError::MissingExtension)?
|
|
|
|
.to_owned();
|
|
|
|
let ext = from_ext(ext);
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// If the thumbnail doesn't exist, we need to create it
|
2020-06-06 21:02:26 +00:00
|
|
|
if let Err(e) = actix_fs::metadata(path.clone()).await {
|
|
|
|
if e.kind() != Some(std::io::ErrorKind::NotFound) {
|
2020-06-07 17:51:45 +00:00
|
|
|
error!("Error looking up processed image, {}", e);
|
2020-06-06 21:02:26 +00:00
|
|
|
return Err(e.into());
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
let mut original_path = manager.image_dir();
|
2020-06-06 21:02:26 +00:00
|
|
|
original_path.push(name.clone());
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Read the image file & produce a DynamicImage
|
|
|
|
//
|
|
|
|
// Drop bytes so we don't keep it around in memory longer than we need to
|
2020-06-14 02:28:06 +00:00
|
|
|
debug!("Reading image");
|
2020-06-06 21:02:26 +00:00
|
|
|
let (img, format) = {
|
|
|
|
let bytes = actix_fs::read(original_path.clone()).await?;
|
2020-06-14 02:28:06 +00:00
|
|
|
let bytes2 = bytes.clone();
|
|
|
|
let format = web::block(move || image::guess_format(&bytes2)).await?;
|
2020-06-06 21:41:17 +00:00
|
|
|
let img = web::block(move || image::load_from_memory(&bytes)).await?;
|
2020-06-06 21:02:26 +00:00
|
|
|
|
|
|
|
(img, format)
|
|
|
|
};
|
|
|
|
|
2020-06-14 02:28:06 +00:00
|
|
|
debug!("Processing image");
|
2020-06-14 15:07:31 +00:00
|
|
|
let img = self::processor::process_image(chain, img).await?;
|
2020-06-06 21:02:26 +00:00
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// perform thumbnail operation in a blocking thread
|
2020-06-14 02:28:06 +00:00
|
|
|
debug!("Exporting image");
|
2020-06-06 21:02:26 +00:00
|
|
|
let img_bytes: bytes::Bytes = web::block(move || {
|
|
|
|
let mut bytes = std::io::Cursor::new(vec![]);
|
2020-06-15 02:41:45 +00:00
|
|
|
img.write_to(&mut bytes, convert_format(format)?)?;
|
|
|
|
Ok(bytes::Bytes::from(bytes.into_inner())) as Result<_, UploadError>
|
2020-06-06 21:02:26 +00:00
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let path2 = path.clone();
|
|
|
|
let img_bytes2 = img_bytes.clone();
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Save the file in another task, we want to return the thumbnail now
|
2020-06-14 15:07:31 +00:00
|
|
|
debug!("Spawning storage task");
|
|
|
|
let span = Span::current();
|
2020-06-06 21:02:26 +00:00
|
|
|
actix_rt::spawn(async move {
|
2020-06-14 15:07:31 +00:00
|
|
|
let entered = span.enter();
|
2020-06-09 23:39:49 +00:00
|
|
|
if let Err(e) = manager.store_variant(path2.clone()).await {
|
|
|
|
error!("Error storing variant, {}", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
if let Err(e) = safe_save_file(path2, img_bytes2).await {
|
|
|
|
error!("Error saving file, {}", e);
|
2020-06-06 21:02:26 +00:00
|
|
|
}
|
2020-06-14 15:07:31 +00:00
|
|
|
drop(entered);
|
2020-06-06 21:02:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return Ok(srv_response(
|
|
|
|
Box::pin(futures::stream::once(async {
|
|
|
|
Ok(img_bytes) as Result<_, UploadError>
|
|
|
|
})),
|
|
|
|
ext,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
let stream = actix_fs::read_to_stream(path).await?;
|
|
|
|
|
|
|
|
Ok(srv_response(stream, ext))
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// A helper method to produce responses with proper cache headers
|
2020-06-06 21:02:26 +00:00
|
|
|
fn srv_response<S, E>(stream: S, ext: mime::Mime) -> HttpResponse
|
|
|
|
where
|
|
|
|
S: Stream<Item = Result<bytes::Bytes, E>> + Unpin + 'static,
|
|
|
|
E: Into<UploadError>,
|
|
|
|
{
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.set(CacheControl(vec![
|
|
|
|
CacheDirective::Public,
|
|
|
|
CacheDirective::MaxAge(24 * HOURS),
|
|
|
|
CacheDirective::Extension("immutable".to_owned(), None),
|
|
|
|
]))
|
|
|
|
.content_type(ext.to_string())
|
|
|
|
.streaming(stream.err_into())
|
|
|
|
}
|
|
|
|
|
2020-06-07 15:59:58 +00:00
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
struct UrlQuery {
|
|
|
|
url: String,
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:02:26 +00:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> Result<(), anyhow::Error> {
|
2020-06-14 02:28:06 +00:00
|
|
|
if std::env::var("RUST_LOG").is_err() {
|
|
|
|
std::env::set_var("RUST_LOG", "info");
|
|
|
|
}
|
|
|
|
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
|
|
.init();
|
|
|
|
|
2020-06-14 15:07:31 +00:00
|
|
|
let manager = UploadManager::new(CONFIG.data_dir(), CONFIG.format()).await?;
|
2020-06-06 21:02:26 +00:00
|
|
|
|
2020-06-06 21:41:17 +00:00
|
|
|
// Create a new Multipart Form validator
|
|
|
|
//
|
|
|
|
// This form is expecting a single array field, 'images' with at most 10 files in it
|
2020-06-06 21:02:26 +00:00
|
|
|
let manager2 = manager.clone();
|
|
|
|
let form = Form::new()
|
|
|
|
.max_files(10)
|
2020-06-14 15:07:31 +00:00
|
|
|
.max_file_size(CONFIG.max_file_size() * MEGABYTES)
|
2020-06-13 19:04:33 +00:00
|
|
|
.transform_error(|e| UploadError::from(e).into())
|
2020-06-06 21:02:26 +00:00
|
|
|
.field(
|
|
|
|
"images",
|
2020-06-14 18:56:42 +00:00
|
|
|
Field::array(Field::file(move |filename, _, stream| {
|
2020-06-06 21:02:26 +00:00
|
|
|
let manager = manager2.clone();
|
|
|
|
|
2020-06-07 15:59:58 +00:00
|
|
|
async move {
|
2020-06-14 18:56:42 +00:00
|
|
|
let span = tracing::info_span!("file-upload", ?filename);
|
|
|
|
let entered = span.enter();
|
|
|
|
|
|
|
|
let res = manager.upload(stream).await.map(|alias| {
|
2020-06-07 15:59:58 +00:00
|
|
|
let mut path = PathBuf::new();
|
|
|
|
path.push(alias);
|
|
|
|
Some(path)
|
2020-06-14 18:56:42 +00:00
|
|
|
});
|
|
|
|
drop(entered);
|
|
|
|
res
|
2020-06-07 15:59:58 +00:00
|
|
|
}
|
2020-06-06 21:02:26 +00:00
|
|
|
})),
|
|
|
|
);
|
|
|
|
|
2020-06-11 00:26:54 +00:00
|
|
|
// Create a new Multipart Form validator for internal imports
|
|
|
|
//
|
|
|
|
// This form is expecting a single array field, 'images' with at most 10 files in it
|
2020-06-14 15:07:31 +00:00
|
|
|
let validate_imports = CONFIG.validate_imports();
|
2020-06-11 00:26:54 +00:00
|
|
|
let manager2 = manager.clone();
|
|
|
|
let import_form = Form::new()
|
|
|
|
.max_files(10)
|
2020-06-14 15:07:31 +00:00
|
|
|
.max_file_size(CONFIG.max_file_size() * MEGABYTES)
|
2020-06-13 19:04:33 +00:00
|
|
|
.transform_error(|e| UploadError::from(e).into())
|
2020-06-11 00:26:54 +00:00
|
|
|
.field(
|
|
|
|
"images",
|
|
|
|
Field::array(Field::file(move |filename, content_type, stream| {
|
|
|
|
let manager = manager2.clone();
|
|
|
|
|
|
|
|
async move {
|
2020-06-14 18:56:42 +00:00
|
|
|
let span = tracing::info_span!("file-import", ?filename);
|
|
|
|
let entered = span.enter();
|
|
|
|
|
|
|
|
let res = manager
|
2020-06-14 15:07:31 +00:00
|
|
|
.import(filename, content_type, validate_imports, stream)
|
2020-06-11 00:26:54 +00:00
|
|
|
.await
|
|
|
|
.map(|alias| {
|
|
|
|
let mut path = PathBuf::new();
|
|
|
|
path.push(alias);
|
|
|
|
Some(path)
|
2020-06-14 18:56:42 +00:00
|
|
|
});
|
|
|
|
drop(entered);
|
|
|
|
res
|
2020-06-11 00:26:54 +00:00
|
|
|
}
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
|
2020-06-06 21:02:26 +00:00
|
|
|
HttpServer::new(move || {
|
2020-06-07 15:59:58 +00:00
|
|
|
let client = Client::build()
|
|
|
|
.header("User-Agent", "pict-rs v0.1.0-master")
|
|
|
|
.finish();
|
|
|
|
|
2020-06-06 21:02:26 +00:00
|
|
|
App::new()
|
2020-06-07 02:14:31 +00:00
|
|
|
.wrap(Compress::default())
|
2020-06-14 02:28:06 +00:00
|
|
|
.wrap(Logger::default())
|
|
|
|
.wrap(Tracing)
|
2020-06-06 21:02:26 +00:00
|
|
|
.data(manager.clone())
|
2020-06-07 15:59:58 +00:00
|
|
|
.data(client)
|
2020-06-14 15:07:31 +00:00
|
|
|
.data(CONFIG.filter_whitelist())
|
2020-06-06 21:02:26 +00:00
|
|
|
.service(
|
|
|
|
web::scope("/image")
|
|
|
|
.service(
|
|
|
|
web::resource("")
|
|
|
|
.guard(guard::Post())
|
|
|
|
.wrap(form.clone())
|
|
|
|
.route(web::post().to(upload)),
|
|
|
|
)
|
2020-06-07 15:59:58 +00:00
|
|
|
.service(web::resource("/download").route(web::get().to(download)))
|
2020-06-07 00:29:15 +00:00
|
|
|
.service(
|
|
|
|
web::resource("/delete/{delete_token}/{filename}")
|
2020-06-09 22:37:48 +00:00
|
|
|
.route(web::delete().to(delete))
|
|
|
|
.route(web::get().to(delete)),
|
2020-06-07 00:29:15 +00:00
|
|
|
)
|
2020-06-07 17:51:45 +00:00
|
|
|
.service(web::resource("/{tail:.*}").route(web::get().to(serve))),
|
2020-06-06 21:02:26 +00:00
|
|
|
)
|
2020-06-11 00:26:54 +00:00
|
|
|
.service(
|
|
|
|
web::resource("/import")
|
|
|
|
.wrap(import_form.clone())
|
|
|
|
.route(web::post().to(upload)),
|
|
|
|
)
|
2020-06-06 21:02:26 +00:00
|
|
|
})
|
2020-06-14 15:07:31 +00:00
|
|
|
.bind(CONFIG.bind_address())?
|
2020-06-06 21:02:26 +00:00
|
|
|
.run()
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|