Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions crates/archive/src/extractors/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ pub fn list_tar_entries<P: AsRef<Path>>(path: P) -> Result<Vec<Extract>, Archive
let is_dir = header.entry_type().is_dir();

let dt = UNIX_EPOCH + Duration::from_secs(mtime);
let last_modified = format!(
"{}",
chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339()
);
let last_modified = chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339();

entries.push(Extract::new(name, size, last_modified, is_dir));
}
Expand All @@ -49,10 +46,7 @@ pub fn list_tar_gz_entries<P: AsRef<Path>>(path: P) -> Result<Vec<Extract>, Arch
let is_dir = header.entry_type().is_dir();

let dt = UNIX_EPOCH + Duration::from_secs(mtime);
let last_modified = format!(
"{}",
chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339()
);
let last_modified = chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339();

entries.push(Extract::new(name, size, last_modified, is_dir));
}
Expand All @@ -77,10 +71,7 @@ pub fn list_tar_bz2_entries<P: AsRef<Path>>(path: P) -> Result<Vec<Extract>, Arc
let is_dir = header.entry_type().is_dir();

let dt = UNIX_EPOCH + Duration::from_secs(mtime);
let last_modified = format!(
"{}",
chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339()
);
let last_modified = chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339();

entries.push(Extract::new(name, size, last_modified, is_dir));
}
Expand All @@ -105,10 +96,7 @@ pub fn list_tar_xz_entries<P: AsRef<Path>>(path: P) -> Result<Vec<Extract>, Arch
let is_dir = header.entry_type().is_dir();

let dt = UNIX_EPOCH + Duration::from_secs(mtime);
let last_modified = format!(
"{}",
chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339()
);
let last_modified = chrono::DateTime::<chrono::Local>::from(dt).to_rfc3339();

entries.push(Extract::new(name, size, last_modified, is_dir));
}
Expand Down
10 changes: 2 additions & 8 deletions crates/docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ fn excel(file_path: &str) -> Result<Vec<DSheet>, Box<dyn std::error::Error>> {
let range = workbook.worksheet_range(&sheet)?;
let mut rows = Vec::new();
for row in range.rows() {
let mut cell_list: Vec<String> = Vec::new();
for cell in row.iter() {
cell_list.push(cell.to_string());
}
let cell_list: Vec<String> = row.iter().map(|cell| cell.to_string()).collect();
rows.push(cell_list);
}
let map = DSheet { name: sheet, rows };
Expand All @@ -65,10 +62,7 @@ fn csv(file_path: &str) -> Result<Vec<DSheet>, Box<dyn std::error::Error>> {
let mut rows: Vec<Vec<String>> = vec![];
for result in rdr.records() {
let record = result?;
let mut cols: Vec<String> = Vec::new();
for i in 0..record.len() {
cols.push(record[i].to_string());
}
let cols: Vec<String> = record.iter().map(|s| s.to_string()).collect();
rows.push(cols);
}
let target: Vec<DSheet> = vec![DSheet { name: "sheet1".to_string(), rows }];
Expand Down
24 changes: 11 additions & 13 deletions src-tauri/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,29 @@ pub fn set_log_level(level: usize) -> Result<(), String> {

#[command]
pub fn psd_to_png(path: &str) -> Result<String, String> {
let file_bytes = std::fs::read(path);
let file_bytes = std::fs::read(path).map_err(|e| {
log::info!("psd:: 读取文件失败");
e.to_string()
})?;

if file_bytes.is_err() {
log::info!("psd:: 读取文件失败")
}

let psd_obj = psd::Psd::from_bytes(&*file_bytes.unwrap());
if psd_obj.is_err() {
log::info!("psd:: 从 bytes 解析 错误")
}
let psd_obj = psd_obj.unwrap();
let psd_obj = psd::Psd::from_bytes(&file_bytes).map_err(|e| {
log::info!("psd:: 从 bytes 解析 错误");
e.to_string()
})?;

let rgba = psd_obj.rgba();
// 封装成 RgbaImage
let width = psd_obj.width();
let height = psd_obj.height();
let img = image::RgbaImage::from_raw(width, height, rgba);
let img = image::RgbaImage::from_raw(width, height, rgba)
.ok_or_else(|| "PSD 图像数据尺寸与像素数据不匹配".to_string())?;

// Windows 临时目录
let mut temp_path: PathBuf = std::env::temp_dir();
temp_path.push("quicklook_psd_preview.png"); // 固定文件名

// 保存为 PNG
img.unwrap()
.save_with_format(&temp_path, image::ImageFormat::Png)
img.save_with_format(&temp_path, image::ImageFormat::Png)
.map_err(|e| e.to_string())?;

// 返回文件路径给前端
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/helper/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ pub fn read_music_info<P: AsRef<Path>>(path: P) -> Option<MusicInfo> {
let props = AudioFile::properties(&tagged_file);

// 提取封面(APIC / covr 等)
let cover = tag.and_then(|t| t.pictures().get(0).map(|pic| pic.data().to_vec()));
let cover = tag.and_then(|t| t.pictures().first().map(|pic| pic.data().to_vec()));
let title = tag.and_then(|t| t.get_string(ItemKey::TrackTitle).map(|s| s.to_string()));
let artist = tag.and_then(|t| t.get_string(ItemKey::TrackArtist).map(|s| s.to_string()));
let album = tag.and_then(|t| t.get_string(ItemKey::AlbumTitle).map(|s| s.to_string()));
let music_info = MusicInfo {
title: title,
artist: artist,
album: album,
title,
artist,
album,
duration: Some(props.duration().as_secs()),
bitrate: props.audio_bitrate().map(|b| b / 1000), // 转换为 kbps
cover,
Expand Down
158 changes: 29 additions & 129 deletions src-tauri/src/helper/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,145 +24,45 @@ pub struct Config {
pub book_checked: Vec<String>,
}

/// 从 JSON 对象中提取字符串数组字段
fn extract_str_vec(
config: &serde_json::Map<String, Value>,
key: &str,
) -> Result<Vec<String>, String> {
config
.get(key)
.and_then(|v| v.as_array())
.map(|arr| arr.iter().filter_map(|v| v.as_str().map(|s| s.to_string())).collect())
.ok_or_else(|| format!("config.json: 缺少或类型错误的键 \"{}\"", key))
}

#[allow(unused)]
pub fn read_config(app: &AppHandle) -> Result<Config, String> {
let config_path = app
.path()
.resolve("config.json", BaseDirectory::Resource)
.unwrap();
.map_err(|e| e.to_string())?;

let file = File::open(config_path).map_err(|e| e.to_string())?;
let reader = BufReader::new(file);
let config: Value = serde_json::from_reader(reader).map_err(|e| e.to_string())?;
let config = config.as_object().ok_or("config.json is not an object")?;
Ok(Config {
markdown: config
.get("preview.markdown")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
markdown_checked: config
.get("preview.markdown.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
image: config
.get("preview.image")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
image_checked: config
.get("preview.image.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
video: config
.get("preview.video")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
video_checked: config
.get("preview.video.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
doc: config
.get("preview.doc")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
doc_checked: config
.get("preview.doc.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
code: config
.get("preview.code")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
code_checked: config
.get("preview.code.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
font: config
.get("preview.font")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
font_checked: config
.get("preview.font.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
archive: config
.get("preview.archive")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
archive_checked: config
.get("preview.archive.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
book: config
.get("preview.book")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
book_checked: config
.get("preview.book.checked")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect(),
markdown: extract_str_vec(config, "preview.markdown")?,
markdown_checked: extract_str_vec(config, "preview.markdown.checked")?,
image: extract_str_vec(config, "preview.image")?,
image_checked: extract_str_vec(config, "preview.image.checked")?,
video: extract_str_vec(config, "preview.video")?,
video_checked: extract_str_vec(config, "preview.video.checked")?,
doc: extract_str_vec(config, "preview.doc")?,
doc_checked: extract_str_vec(config, "preview.doc.checked")?,
code: extract_str_vec(config, "preview.code")?,
code_checked: extract_str_vec(config, "preview.code.checked")?,
font: extract_str_vec(config, "preview.font")?,
font_checked: extract_str_vec(config, "preview.font.checked")?,
archive: extract_str_vec(config, "preview.archive")?,
archive_checked: extract_str_vec(config, "preview.archive.checked")?,
book: extract_str_vec(config, "preview.book")?,
book_checked: extract_str_vec(config, "preview.book.checked")?,
})
}
8 changes: 3 additions & 5 deletions src-tauri/src/helper/ffmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ pub fn convert_video_to_hls(path: &str) -> Result<String, String> {
// 如果已是 h264,直接复制视频流;否则转码为 libx264
let video_codec = if codec == "h264" { "copy" } else { "libx264" };

let seg_filename = "seg_%03d.ts".to_string();
let m3u8_file_name = "index.m3u8".to_string();
let mut hls_base_url = format!("{}", temp_dir.to_string_lossy().replace('\\', "/"));
let mut hls_base_url = temp_dir.to_string_lossy().replace('\\', "/");
if !hls_base_url.ends_with('/') {
hls_base_url.push('/');
}
Expand Down Expand Up @@ -175,10 +173,10 @@ pub fn convert_video_to_hls(path: &str) -> Result<String, String> {
"-hls_base_url",
&hls_base_url,
"-hls_segment_filename",
&seg_filename,
"seg_%03d.ts",
"-f",
"hls",
&m3u8_file_name,
"index.m3u8",
])
.spawn()
.map_err(|e| e.to_string())?;
Expand Down
12 changes: 1 addition & 11 deletions src-tauri/src/helper/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@ use windows::Win32::{
Graphics::Gdi::{GetDC, GetDeviceCaps, ReleaseDC, HORZRES, LOGPIXELSX, VERTRES},
};

#[derive(Debug, serde::Serialize, Clone)]
#[derive(Debug, serde::Serialize, Clone, Default)]
pub struct MonitorInfo {
pub width: f64,
pub height: f64,
pub scale: f64,
}

impl Default for MonitorInfo {
fn default() -> Self {
Self {
width: Default::default(),
height: Default::default(),
scale: Default::default(),
}
}
}

#[allow(dead_code)]
pub fn get_monitor_info() -> MonitorInfo {
let hwnd = HWND(null_mut());
Expand Down
Loading
Loading