Merge branch 'develop' into feature/unit_tests

This commit is contained in:
Jörn-Michael Miehe 2025-07-10 13:24:13 +00:00
commit 47ad51f860
5 changed files with 44 additions and 46 deletions

View file

@ -1,15 +1,16 @@
// TODO fix with documentation
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
mod appstate;
mod cachefile;
mod cli;
mod error;
mod file;
mod impl_ureq;
pub mod output;
mod sharry;
mod test_util;
mod ureq_client;
pub use appstate::AppState;
pub use cli::Cli;

View file

@ -7,7 +7,7 @@ use log::{info, warn};
type StaticStyled<'t> = LazyLock<StyledObject<&'t str>>;
pub static SHRUPL: StaticStyled = LazyLock::new(|| style("ShrUpl").yellow().bold());
pub const SHRUPL: StaticStyled = LazyLock::new(|| style("ShrUpl").yellow().bold());
#[must_use]
pub fn prompt_continue() -> bool {
@ -61,7 +61,6 @@ where
}
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn new_progressbar() -> ProgressBar {
ProgressBar::no_length().with_style(
ProgressStyle::with_template(&format!(

View file

@ -71,27 +71,25 @@ impl fmt::Display for FileID {
}
}
/// Pattern breakdown:
/// - `^([^:/?#]+)://` - scheme (anything but `:/?#`) + `"://"`
/// - `([^/?#]+)` - authority/host (anything but `/?#`)
/// - `/api/v2/alias/upload/` - literal path segment
/// - `([^/]+)` - capture SID (one or more non-slash chars)
/// - `/files/tus/` - literal path segment
/// - `(?P<fid>[^/]+)` - capture FID (one or more non-slash chars)
/// - `$` - end of string
const UPLOAD_URL_RE: LazyLock<Regex> = LazyLock::new(|| {
trace!("compiling UPLOAD_URL_RE");
Regex::new(r"^([^:/?#]+)://([^/?#]+)/api/v2/alias/upload/[^/]+/files/tus/(?P<fid>[^/]+)$")
.expect("Regex compilation failed")
});
impl TryFrom<String> for FileID {
type Error = crate::Error;
fn try_from(value: String) -> crate::Result<Self> {
/// Pattern breakdown:
/// - `^([^:/?#]+)://` - scheme (anything but `:/?#`) + `"://"`
/// - `([^/?#]+)` - authority/host (anything but `/?#`)
/// - `/api/v2/alias/upload/` - literal path segment
/// - `([^/]+)` - capture SID (one or more non-slash chars)
/// - `/files/tus/` - literal path segment
/// - `(?P<fid>[^/]+)` - capture FID (one or more non-slash chars)
/// - `$` - end of string
static UPLOAD_URL_RE: LazyLock<Regex> = LazyLock::new(|| {
trace!("compiling UPLOAD_URL_RE");
Regex::new(
r"^([^:/?#]+)://([^/?#]+)/api/v2/alias/upload/[^/]+/files/tus/(?P<fid>[^/]+)$",
)
.expect("Regex compilation failed")
});
trace!("TryFrom {value:?}");
if let Some(fid) = UPLOAD_URL_RE

View file

@ -1,7 +1,7 @@
use std::{fmt, sync::LazyLock};
use log::{debug, trace};
use regex::Regex;
use regex::{Captures, Regex};
use serde::{Deserialize, Serialize};
/// ID of a file in a Sharry share
@ -26,33 +26,33 @@ impl AsRef<[u8]> for Uri {
}
}
impl From<String> for Uri {
fn from(value: String) -> Self {
fn parse_url(value: &str) -> Option<(String, String)> {
/// Pattern breakdown:
/// - `^(?P<scheme>[^:/?#]+)://` - capture scheme (anything but `:/?#`) + `"://"`
/// - `(?P<host>[^/?#]+)` - capture authority/host (anything but `/?#`)
/// - `(/.*)?` - maybe trailing slash and some path
/// - `$` - end of string
static SHARRY_URI_RE: LazyLock<Regex> = LazyLock::new(|| {
trace!("compiling SHARRY_URI_RE");
Regex::new(r"^(?P<scheme>[^:/?#]+)://(?P<host>[^/?#]+)(/.*)?$")
.expect("Regex compilation failed")
});
SHARRY_URI_RE.captures(value).map(|caps| {
let captured = |name| {
fn captured(caps: &Captures, name: &str) -> String {
caps.name(name)
.unwrap_or_else(|| panic!("{name} not captured"))
.as_str()
.to_string()
};
}
(captured("scheme"), captured("host"))
})
}
/// Pattern breakdown:
/// - `^(?P<scheme>[^:/?#]+)://` - capture scheme (anything but `:/?#`) + `"://"`
/// - `(?P<host>[^/?#]+)` - capture authority/host (anything but `/?#`)
/// - `(/.*)?` - maybe trailing slash and some path
/// - `$` - end of string
const SHARRY_URI_RE: LazyLock<Regex> = LazyLock::new(|| {
trace!("compiling SHARRY_URI_RE");
Regex::new(r"^(?P<scheme>[^:/?#]+)://(?P<host>[^/?#]+)(/.*)?$")
.expect("Regex compilation failed")
});
fn parse_url(value: &str) -> Option<(String, String)> {
SHARRY_URI_RE
.captures(value)
.map(|caps| (captured(&caps, "scheme"), captured(&caps, "host")))
}
impl From<String> for Uri {
fn from(value: String) -> Self {
trace!("TryFrom {value:?}");
if let Some((scheme, host)) = parse_url(&value) {