mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Clippy lints
This commit is contained in:
parent
68e4f1f4c8
commit
79bd562d8e
7 changed files with 28 additions and 34 deletions
|
@ -127,7 +127,7 @@ impl ResponseError for UploadError {
|
||||||
.content_type("application/json")
|
.content_type("application/json")
|
||||||
.body(
|
.body(
|
||||||
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
||||||
.unwrap_or(r#"{"msg":"Internal Server Error"}"#.to_string()),
|
.unwrap_or_else(|_| r#"{"msg":"Internal Server Error"}"#.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,25 +85,17 @@ where
|
||||||
|
|
||||||
fn parse_details(s: std::borrow::Cow<'_, str>) -> Result<Details, MagickError> {
|
fn parse_details(s: std::borrow::Cow<'_, str>) -> Result<Details, MagickError> {
|
||||||
let mut lines = s.lines();
|
let mut lines = s.lines();
|
||||||
let first = lines.next().ok_or_else(|| MagickError::Format)?;
|
let first = lines.next().ok_or(MagickError::Format)?;
|
||||||
|
|
||||||
let mut segments = first.split('|');
|
let mut segments = first.split('|');
|
||||||
|
|
||||||
let dimensions = segments.next().ok_or_else(|| MagickError::Format)?.trim();
|
let dimensions = segments.next().ok_or(MagickError::Format)?.trim();
|
||||||
tracing::debug!("dimensions: {}", dimensions);
|
tracing::debug!("dimensions: {}", dimensions);
|
||||||
let mut dims = dimensions.split(' ');
|
let mut dims = dimensions.split(' ');
|
||||||
let width = dims
|
let width = dims.next().ok_or(MagickError::Format)?.trim().parse()?;
|
||||||
.next()
|
let height = dims.next().ok_or(MagickError::Format)?.trim().parse()?;
|
||||||
.ok_or_else(|| MagickError::Format)?
|
|
||||||
.trim()
|
|
||||||
.parse()?;
|
|
||||||
let height = dims
|
|
||||||
.next()
|
|
||||||
.ok_or_else(|| MagickError::Format)?
|
|
||||||
.trim()
|
|
||||||
.parse()?;
|
|
||||||
|
|
||||||
let format = segments.next().ok_or_else(|| MagickError::Format)?.trim();
|
let format = segments.next().ok_or(MagickError::Format)?.trim();
|
||||||
tracing::debug!("format: {}", format);
|
tracing::debug!("format: {}", format);
|
||||||
|
|
||||||
if !lines.all(|item| item.ends_with(format)) {
|
if !lines.all(|item| item.ends_with(format)) {
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -23,7 +23,10 @@ use std::{
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
sync::oneshot::{Receiver, Sender},
|
sync::{
|
||||||
|
oneshot::{Receiver, Sender},
|
||||||
|
Semaphore,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use tracing::{debug, error, info, instrument, Span};
|
use tracing::{debug, error, info, instrument, Span};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
@ -72,10 +75,12 @@ static TMP_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
||||||
path
|
path
|
||||||
});
|
});
|
||||||
static CONFIG: Lazy<Config> = Lazy::new(Config::from_args);
|
static CONFIG: Lazy<Config> = Lazy::new(Config::from_args);
|
||||||
static PROCESS_SEMAPHORE: Lazy<tokio::sync::Semaphore> =
|
static PROCESS_SEMAPHORE: Lazy<Semaphore> =
|
||||||
Lazy::new(|| tokio::sync::Semaphore::new(num_cpus::get().saturating_sub(1).max(1)));
|
Lazy::new(|| Semaphore::new(num_cpus::get().saturating_sub(1).max(1)));
|
||||||
static PROCESS_MAP: Lazy<DashMap<PathBuf, Vec<Sender<(Details, web::Bytes)>>>> =
|
static PROCESS_MAP: Lazy<ProcessMap> = Lazy::new(DashMap::new);
|
||||||
Lazy::new(DashMap::new);
|
|
||||||
|
type OutcomeSender = Sender<(Details, web::Bytes)>;
|
||||||
|
type ProcessMap = DashMap<PathBuf, Vec<OutcomeSender>>;
|
||||||
|
|
||||||
struct CancelSafeProcessor<F> {
|
struct CancelSafeProcessor<F> {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
@ -397,7 +402,7 @@ async fn prepare_process(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if alias == "" {
|
if alias.is_empty() {
|
||||||
return Err(UploadError::MissingFilename);
|
return Err(UploadError::MissingFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl ResponseError for ApiError {
|
||||||
.content_type("application/json")
|
.content_type("application/json")
|
||||||
.body(
|
.body(
|
||||||
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
||||||
.unwrap_or(r#"{"msg":"unauthorized"}"#.to_string()),
|
.unwrap_or_else(|_| r#"{"msg":"unauthorized"}"#.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ impl actix_web::error::ResponseError for DeadlineExceeded {
|
||||||
.content_type("application/json")
|
.content_type("application/json")
|
||||||
.body(
|
.body(
|
||||||
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
serde_json::to_string(&serde_json::json!({ "msg": self.to_string() }))
|
||||||
.unwrap_or(r#"{"msg":"request timeout"}"#.to_string()),
|
.unwrap_or_else(|_| r#"{"msg":"request timeout"}"#.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{error::UploadError, ffmpeg::ThumbnailFormat};
|
use crate::{error::UploadError, ffmpeg::ThumbnailFormat};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use tracing::{debug, error, instrument};
|
use tracing::{debug, error, instrument};
|
||||||
|
|
||||||
fn ptos(path: &PathBuf) -> Result<String, UploadError> {
|
fn ptos(path: &Path) -> Result<String, UploadError> {
|
||||||
Ok(path.to_str().ok_or(UploadError::Path)?.to_owned())
|
Ok(path.to_str().ok_or(UploadError::Path)?.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/range.rs
12
src/range.rs
|
@ -14,7 +14,7 @@ use tokio::io::{AsyncReadExt, AsyncSeekExt};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum Range {
|
pub(crate) enum Range {
|
||||||
RangeStart(u64),
|
Start(u64),
|
||||||
SuffixLength(u64),
|
SuffixLength(u64),
|
||||||
Segment(u64, u64),
|
Segment(u64, u64),
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ pub(crate) struct RangeHeader {
|
||||||
impl Range {
|
impl Range {
|
||||||
pub(crate) fn to_content_range(&self, instance_length: u64) -> ContentRange {
|
pub(crate) fn to_content_range(&self, instance_length: u64) -> ContentRange {
|
||||||
match self {
|
match self {
|
||||||
Range::RangeStart(start) => ContentRange(ContentRangeSpec::Bytes {
|
Range::Start(start) => ContentRange(ContentRangeSpec::Bytes {
|
||||||
range: Some((*start, instance_length)),
|
range: Some((*start, instance_length)),
|
||||||
instance_length: Some(instance_length),
|
instance_length: Some(instance_length),
|
||||||
}),
|
}),
|
||||||
|
@ -48,7 +48,7 @@ impl Range {
|
||||||
bytes: Bytes,
|
bytes: Bytes,
|
||||||
) -> impl Stream<Item = Result<Bytes, UploadError>> + Unpin {
|
) -> impl Stream<Item = Result<Bytes, UploadError>> + Unpin {
|
||||||
match self {
|
match self {
|
||||||
Range::RangeStart(start) => once(ready(Ok(bytes.slice(*start as usize..)))),
|
Range::Start(start) => once(ready(Ok(bytes.slice(*start as usize..)))),
|
||||||
Range::SuffixLength(from_start) => once(ready(Ok(bytes.slice(..*from_start as usize)))),
|
Range::SuffixLength(from_start) => once(ready(Ok(bytes.slice(..*from_start as usize)))),
|
||||||
Range::Segment(start, end) => {
|
Range::Segment(start, end) => {
|
||||||
once(ready(Ok(bytes.slice(*start as usize..*end as usize))))
|
once(ready(Ok(bytes.slice(*start as usize..*end as usize))))
|
||||||
|
@ -61,7 +61,7 @@ impl Range {
|
||||||
mut file: tokio::fs::File,
|
mut file: tokio::fs::File,
|
||||||
) -> Result<LocalBoxStream<'static, Result<Bytes, UploadError>>, UploadError> {
|
) -> Result<LocalBoxStream<'static, Result<Bytes, UploadError>>, UploadError> {
|
||||||
match self {
|
match self {
|
||||||
Range::RangeStart(start) => {
|
Range::Start(start) => {
|
||||||
file.seek(io::SeekFrom::Start(*start)).await?;
|
file.seek(io::SeekFrom::Start(*start)).await?;
|
||||||
|
|
||||||
Ok(Box::pin(bytes_stream(file)))
|
Ok(Box::pin(bytes_stream(file)))
|
||||||
|
@ -87,7 +87,7 @@ impl RangeHeader {
|
||||||
self.unit == "bytes"
|
self.unit == "bytes"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ranges<'a>(&'a self) -> impl Iterator<Item = &'a Range> + 'a {
|
pub(crate) fn ranges(&self) -> impl Iterator<Item = &'_ Range> + '_ {
|
||||||
self.ranges.iter()
|
self.ranges.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ fn parse_range(s: &str) -> Result<Range, UploadError> {
|
||||||
UploadError::ParseReq("Cannot parse range start for range header".to_string())
|
UploadError::ParseReq("Cannot parse range start for range header".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Range::RangeStart(range_start))
|
Ok(Range::Start(range_start))
|
||||||
} else {
|
} else {
|
||||||
let range_start = start.parse().map_err(|_| {
|
let range_start = start.parse().map_err(|_| {
|
||||||
UploadError::ParseReq("Cannot parse range start for range header".to_string())
|
UploadError::ParseReq("Cannot parse range start for range header".to_string())
|
||||||
|
|
|
@ -632,10 +632,7 @@ impl UploadManagerSession {
|
||||||
/// Generate a delete token for an alias
|
/// Generate a delete token for an alias
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub(crate) async fn delete_token(&self) -> Result<String, UploadError> {
|
pub(crate) async fn delete_token(&self) -> Result<String, UploadError> {
|
||||||
let alias = self
|
let alias = self.alias.clone().ok_or(UploadError::MissingAlias)?;
|
||||||
.alias
|
|
||||||
.clone()
|
|
||||||
.ok_or_else(|| UploadError::MissingAlias)?;
|
|
||||||
|
|
||||||
debug!("Generating delete token");
|
debug!("Generating delete token");
|
||||||
use rand::distributions::{Alphanumeric, Distribution};
|
use rand::distributions::{Alphanumeric, Distribution};
|
||||||
|
|
Loading…
Reference in a new issue