chore: update actix deps, get rid of one future incompat warning
parent
c2b8df9aaa
commit
69d1059739
File diff suppressed because it is too large
Load Diff
|
@ -32,12 +32,13 @@ diesel = { version = "1.4", features = [
|
|||
diesel_migrations = "1.4"
|
||||
libsqlite3-sys = { version = "^0", features = ["bundled"] }
|
||||
|
||||
actix = "^0.10"
|
||||
actix-files = "^0.5"
|
||||
actix-rt = "^2.0"
|
||||
actix-web = "^3.3"
|
||||
actix_derive = "^0.5"
|
||||
actix-cors = "0.5"
|
||||
actix = "0.13"
|
||||
actix-files = "0.6"
|
||||
actix-rt = "2"
|
||||
actix-web = "4"
|
||||
actix_derive = "0.6"
|
||||
actix-cors = "0.6"
|
||||
actix-multipart = "0.6.0"
|
||||
jsonwebtoken = "8"
|
||||
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
@ -69,7 +70,6 @@ is_executable = { version = "1.0.1", optional = true }
|
|||
webbrowser = { version = "^0.5.5", optional = true }
|
||||
|
||||
nonempty = "0.6.0"
|
||||
actix-multipart = "0.3.0"
|
||||
|
||||
image = { version = "0.23.14", optional = true }
|
||||
webp = { version = "0.2.0", optional = true }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#[macro_use]
|
||||
extern crate upend;
|
||||
use actix_cors::Cors;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{middleware, App, HttpServer};
|
||||
use anyhow::Result;
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
|
@ -167,7 +168,8 @@ struct ServeArgs {
|
|||
allow_host: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
#[actix_web::main]
|
||||
async fn main() -> Result<()> {
|
||||
let args = Cli::parse();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
|
@ -288,7 +290,6 @@ fn main() -> Result<()> {
|
|||
}
|
||||
Commands::Serve(args) => {
|
||||
info!("Starting UpEnd {}...", build::PKG_VERSION);
|
||||
let sys = actix::System::new("upend");
|
||||
|
||||
let job_container = JobContainer::new();
|
||||
|
||||
|
@ -406,7 +407,7 @@ fn main() -> Result<()> {
|
|||
let app = App::new()
|
||||
.wrap(cors)
|
||||
.app_data(actix_web::web::PayloadConfig::new(4_294_967_296))
|
||||
.data(state.clone())
|
||||
.app_data(Data::new(state.clone()))
|
||||
.wrap(middleware::Logger::default().exclude("/api/jobs"))
|
||||
.service(routes::login)
|
||||
.service(routes::get_raw)
|
||||
|
@ -457,9 +458,6 @@ fn main() -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
info!("Starting server at: {}", &bind);
|
||||
server.run();
|
||||
|
||||
if !args.no_initial_update {
|
||||
info!("Running initial update...");
|
||||
let initial = open_result.new;
|
||||
|
@ -480,7 +478,9 @@ fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(sys.run()?)
|
||||
info!("Starting server at: {}", &bind);
|
||||
server.run().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,11 @@ use actix_web::error::{
|
|||
ErrorBadRequest, ErrorInternalServerError, ErrorNotFound, ErrorUnauthorized,
|
||||
ErrorUnprocessableEntity,
|
||||
};
|
||||
use actix_web::http::header::ContentDisposition;
|
||||
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
||||
use actix_web::{http, Responder};
|
||||
use actix_web::{
|
||||
http::header::{CacheControl, CacheDirective, ContentDisposition, DispositionType},
|
||||
http::header::{CacheControl, CacheDirective, DispositionType},
|
||||
HttpRequest,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
|
@ -134,13 +135,13 @@ pub async fn get_raw(
|
|||
let _hash = hash.clone();
|
||||
let _store = state.store.clone();
|
||||
let blobs = web::block(move || _store.retrieve(_hash.as_ref()))
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
if let Some(blob) = blobs.get(0) {
|
||||
let file_path = blob.get_file_path();
|
||||
|
||||
if query.native.is_none() {
|
||||
return Ok(Either::A(
|
||||
return Ok(Either::Left(
|
||||
NamedFile::open(file_path)?
|
||||
.set_content_disposition(ContentDisposition {
|
||||
disposition: if query.inline.is_some() {
|
||||
|
@ -150,13 +151,14 @@ pub async fn get_raw(
|
|||
},
|
||||
parameters: vec![],
|
||||
})
|
||||
.with_header(
|
||||
.customize()
|
||||
.insert_header((
|
||||
http::header::CACHE_CONTROL,
|
||||
CacheControl(vec![
|
||||
CacheDirective::MaxAge(2678400),
|
||||
CacheDirective::Extension("immutable".into(), None),
|
||||
]),
|
||||
),
|
||||
)),
|
||||
));
|
||||
} else if state.config.desktop_enabled {
|
||||
#[cfg(feature = "desktop")]
|
||||
|
@ -167,21 +169,21 @@ pub async fn get_raw(
|
|||
file_path
|
||||
} else {
|
||||
response
|
||||
.header(
|
||||
.append_header((
|
||||
http::header::WARNING,
|
||||
"199 - Opening parent directory due to file being executable.",
|
||||
)
|
||||
.header(
|
||||
))
|
||||
.append_header((
|
||||
http::header::ACCESS_CONTROL_EXPOSE_HEADERS,
|
||||
http::header::WARNING.to_string(),
|
||||
);
|
||||
));
|
||||
|
||||
file_path.parent().ok_or_else(|| {
|
||||
ErrorInternalServerError("No parent to open as fallback.")
|
||||
})?
|
||||
};
|
||||
opener::open(path).map_err(error::ErrorServiceUnavailable)?;
|
||||
return Ok(Either::B(response.finish()));
|
||||
return Ok(Either::Right(response.finish()));
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
|
@ -194,10 +196,10 @@ pub async fn get_raw(
|
|||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
let _hash = hash.clone();
|
||||
let entry = web::block(move || connection.retrieve_entry(_hash.as_ref()))
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
if let Some(entry) = entry {
|
||||
return Ok(Either::B(HttpResponse::Ok().json(entry)));
|
||||
return Ok(Either::Right(HttpResponse::Ok().json(entry)));
|
||||
}
|
||||
|
||||
Err(error::ErrorNotFound("NOT FOUND"))
|
||||
|
@ -237,11 +239,11 @@ pub async fn get_thumbnail(
|
|||
file = file.set_content_type(mime);
|
||||
}
|
||||
}
|
||||
return Ok(Either::A(file));
|
||||
return Ok(Either::Left(file));
|
||||
} else {
|
||||
return Ok(Either::B(
|
||||
return Ok(Either::Right(
|
||||
HttpResponse::SeeOther()
|
||||
.header(http::header::LOCATION, format!("../../api/raw/{hash}"))
|
||||
.append_header((http::header::LOCATION, format!("../../api/raw/{hash}")))
|
||||
.finish(),
|
||||
));
|
||||
}
|
||||
|
@ -261,6 +263,7 @@ pub async fn get_query(state: web::Data<State>, query: String) -> Result<HttpRes
|
|||
let in_query: Query = query.parse().map_err(ErrorBadRequest)?;
|
||||
let entries = web::block(move || connection.query(in_query))
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
let mut result: HashMap<String, Entry> = HashMap::new();
|
||||
for entry in entries {
|
||||
|
@ -304,7 +307,7 @@ pub async fn get_object(
|
|||
|
||||
let _address = address.clone();
|
||||
let result: Vec<Entry> = web::block(move || connection.retrieve_object(&_address))
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
debug!("{:?}", result);
|
||||
|
@ -419,13 +422,13 @@ pub async fn put_object(
|
|||
match in_entry {
|
||||
PutInput::Entry(in_entry) => {
|
||||
let entry = process_inentry(in_entry).map_err(ErrorBadRequest)?;
|
||||
web::block::<_, _, anyhow::Error>(move || {
|
||||
web::block::<_, Result<_>>(move || {
|
||||
Ok((
|
||||
Some(connection.insert_entry(entry.clone())?),
|
||||
Some(entry.entity),
|
||||
))
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?
|
||||
}
|
||||
PutInput::EntryList(entries) => {
|
||||
|
@ -437,7 +440,7 @@ pub async fn put_object(
|
|||
Ok(())
|
||||
})
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorBadRequest)?;
|
||||
|
||||
(None, None)
|
||||
|
@ -499,7 +502,7 @@ pub async fn put_object(
|
|||
Ok((None, Some(address)))
|
||||
})
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?
|
||||
}
|
||||
}
|
||||
|
@ -517,15 +520,11 @@ pub async fn put_blob(
|
|||
check_auth(&req, &state)?;
|
||||
|
||||
if let Some(mut field) = payload.try_next().await? {
|
||||
let content_disposition = field
|
||||
.content_disposition()
|
||||
.ok_or_else(|| HttpResponse::BadRequest().finish())?;
|
||||
|
||||
let filename = content_disposition.get_filename().map(String::from);
|
||||
let filename = field.content_disposition().get_filename().map(String::from);
|
||||
|
||||
let mut file = NamedTempFile::new()?;
|
||||
while let Some(chunk) = field.try_next().await? {
|
||||
file = web::block(move || file.write_all(&chunk).map(|_| file)).await?;
|
||||
file = web::block(move || file.write_all(&chunk).map(|_| file)).await??;
|
||||
}
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
|
@ -534,7 +533,7 @@ pub async fn put_blob(
|
|||
let hash = web::block(move || {
|
||||
_store.store(connection, Blob::from_filepath(file.path()), _filename)
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
let address = Address::Hash(hash);
|
||||
|
@ -567,11 +566,12 @@ pub async fn put_blob(
|
|||
pub async fn put_object_attribute(
|
||||
req: HttpRequest,
|
||||
state: web::Data<State>,
|
||||
web::Path((address, attribute)): web::Path<(Address, String)>,
|
||||
path: web::Path<(Address, String)>,
|
||||
value: web::Json<EntryValue>,
|
||||
web::Query(query): web::Query<UpdateQuery>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
check_auth(&req, &state)?;
|
||||
let (address, attribute) = path.into_inner();
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
|
||||
let new_address = web::block(move || {
|
||||
|
@ -597,7 +597,7 @@ pub async fn put_object_attribute(
|
|||
connection.insert_entry(new_attr_entry)
|
||||
})
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(new_address))
|
||||
|
@ -701,13 +701,13 @@ pub async fn get_address(
|
|||
|
||||
let mut response = HttpResponse::Ok();
|
||||
if immutable {
|
||||
response.set_header(
|
||||
response.append_header((
|
||||
http::header::CACHE_CONTROL,
|
||||
CacheControl(vec![
|
||||
CacheDirective::MaxAge(2678400),
|
||||
CacheDirective::Extension("immutable".into(), None),
|
||||
]),
|
||||
);
|
||||
));
|
||||
}
|
||||
Ok(response.json(format!("{}", address)))
|
||||
}
|
||||
|
@ -716,7 +716,7 @@ pub async fn get_address(
|
|||
pub async fn get_all_attributes(state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
let attributes = web::block(move || connection.get_all_attributes())
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
|
@ -756,7 +756,7 @@ pub async fn list_hier(
|
|||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
if path.is_empty() {
|
||||
Ok(HttpResponse::MovedPermanently()
|
||||
.header(http::header::LOCATION, "../../api/hier_roots")
|
||||
.append_header((http::header::LOCATION, "../../api/hier_roots"))
|
||||
.finish())
|
||||
} else {
|
||||
let upath: UHierPath = path.into_inner().parse().map_err(ErrorBadRequest)?;
|
||||
|
@ -764,11 +764,11 @@ pub async fn list_hier(
|
|||
|
||||
// todo: 500 if actual error occurs
|
||||
let path = web::block(move || resolve_path(&connection, &upath, false))
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorNotFound)?;
|
||||
match path.last() {
|
||||
Some(addr) => Ok(HttpResponse::Found()
|
||||
.header(http::header::LOCATION, format!("../../api/obj/{}", addr))
|
||||
.append_header((http::header::LOCATION, format!("../../api/obj/{}", addr)))
|
||||
.finish()),
|
||||
None => Ok(HttpResponse::NotFound().finish()),
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ pub async fn list_hier_roots(state: web::Data<State>) -> Result<HttpResponse, Er
|
|||
.map(|root| connection.retrieve_object(&root))
|
||||
.collect::<Result<Vec<Vec<Entry>>>>()
|
||||
})
|
||||
.await
|
||||
.await?
|
||||
.map_err(ErrorInternalServerError)?
|
||||
.concat();
|
||||
|
||||
|
|
Loading…
Reference in New Issue