mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
31 lines
741 B
Rust
31 lines
741 B
Rust
use std::hash::Hash;
|
|
|
|
use mlua::{Function, Lua, Table};
|
|
use yazi_config::YAZI;
|
|
use yazi_fs::file::FileRef;
|
|
use yazi_shared::url::{UrlBuf, UrlLike};
|
|
use yazi_shim::Twox128;
|
|
|
|
use super::Utils;
|
|
|
|
impl Utils {
|
|
pub(super) fn file_cache(lua: &Lua) -> mlua::Result<Function> {
|
|
lua.create_function(|_, t: Table| {
|
|
let file: FileRef = t.raw_get("file")?;
|
|
file.borrow(|f| {
|
|
if f.url.parent() == Some(yazi_shared::url::Url::regular(&YAZI.preview.cache_dir)) {
|
|
return Ok(None);
|
|
}
|
|
|
|
let hex = {
|
|
let mut h = Twox128::default();
|
|
f.hash(&mut h);
|
|
t.raw_get("skip").unwrap_or(0usize).hash(&mut h);
|
|
format!("{:x}", h.finish_128())
|
|
};
|
|
|
|
Ok(Some(UrlBuf::from(YAZI.preview.cache_dir.join(hex))))
|
|
})
|
|
})
|
|
}
|
|
}
|