refactor(subscription): extract response decoding

Keep HTTP and persistence in the app. Decode response metadata and framing in the crate, and fall back when the server filename is invalid.
This commit is contained in:
Tunglies
2026-11-30 18:13:49 +08:00
parent a0d4426f0a
commit 1baa72c2f4
10 changed files with 244 additions and 114 deletions
-23
View File
@@ -8,7 +8,6 @@ use serde_yaml_ng::{Mapping, Value};
use std::{
mem::DropGuard,
path::{Path, PathBuf},
str::FromStr,
};
use tokio::io::AsyncWriteExt as _;
@@ -212,16 +211,6 @@ pub fn get_uid(prefix: &str) -> String {
format!("{prefix}{id}")
}
pub fn parse_str<T: FromStr>(target: &str, key: &str) -> Option<T> {
target.split(';').map(str::trim).find_map(|s| {
let mut parts = s.splitn(2, '=');
match (parts.next(), parts.next()) {
(Some(k), Some(v)) if k == key => v.parse::<T>().ok(),
_ => None,
}
})
}
pub fn hex_encode(bytes: &[u8]) -> String {
const HEX: &[u8; 16] = b"0123456789abcdef";
let mut out = String::with_capacity(bytes.len() * 2);
@@ -307,18 +296,6 @@ pub fn mask_err(err: &str) -> String {
result
}
pub fn get_last_part_and_decode(url: &str) -> Option<String> {
let path = url.split('?').next().unwrap_or("");
let segments: Vec<&str> = path.split('/').collect();
let last_segment = segments.last()?;
Some(
percent_encoding::percent_decode_str(last_segment)
.decode_utf8_lossy()
.to_string(),
)
}
pub fn open_file(path: PathBuf) -> Result<()> {
open::that_detached(path.as_os_str())?;
Ok(())