···151151export declare function update_playlist(id: string, name: string, description: string): void
152152export declare function move_playlist(id: string, fromId: string, toId: string, toIndex: number): void
153153/** Returns `None` if the file does not have an image */
154154-export declare function get_modified_timestamp_ms(path: string): number | null
155155-/** Returns `None` if the file does not have an image */
156156-export declare function read_cache_cover_async(path: string, index: number, dateModifiedMs: number, cacheDbPath: string): Promise<Buffer | null>
154154+export declare function read_small_cover_async(path: string, index: number, cacheDbPath: string): Promise<Buffer | null>
157155export interface TrackMd {
158156 name: string
159157 artist: string
+14-20
src-native/tracks/cover.rs
···4949}
50505151/// Returns `None` if the file does not have an image
5252-#[napi(js_name = "get_modified_timestamp_ms")]
5353-#[allow(dead_code)]
5454-fn get_modified_timestamp_ms_js(path: String) -> Result<Option<i64>> {
5555- let modified_timestamp_ms: i64 = match get_modified_timestamp_ms(&path)? {
5656- Some(modified_timestamp_ms) => modified_timestamp_ms.try_into().unwrap(),
5757- None => return Ok(None),
5858- };
5959- Ok(Some(modified_timestamp_ms))
6060-}
6161-6252fn get_modified_timestamp_ms(path: &str) -> Result<Option<u128>> {
6353 let file_metadata = match fs::metadata(path) {
6454 Ok(file_metadata) => file_metadata,
···124114}
125115126116/// Returns `None` if the file does not have an image
127127-#[napi(js_name = "read_cache_cover_async")]
117117+#[napi(js_name = "read_small_cover_async")]
128118#[allow(dead_code)]
129129-pub async fn read_cache_cover_async(
119119+pub async fn read_small_cover_async(
130120 path: String,
131121 index: u16,
132132- date_modified_ms: i64,
133122 cache_db_path: String,
134123) -> Result<Option<Buffer>> {
135135- if date_modified_ms <= 0 {
136136- throw!("date_modified_ms must be greater than 0")
137137- } else if path == "" {
124124+ if path == "" {
138125 throw!("path must not be empty")
139126 } else if cache_db_path == "" {
140127 throw!("cache_db_path must not be empty")
···145132 let cache_db_mutex = CACHE_DB.read().unwrap();
146133 let cache_db = cache_db_mutex.as_ref().unwrap();
147134148148- if let Some(img_bytes) = get_cached_image(cache_db, &path, date_modified_ms)? {
149149- return Ok(Some(img_bytes.into()));
135135+ let date_modified_ms: Option<i64> =
136136+ get_modified_timestamp_ms(&path)?.map(|n| n.try_into().unwrap());
137137+138138+ if let Some(date_modified_ms) = date_modified_ms {
139139+ if let Some(img_bytes) = get_cached_image(cache_db, &path, date_modified_ms)? {
140140+ return Ok(Some(img_bytes.into()));
141141+ }
150142 }
151143152144 let tag = Tag::read_from_path(&PathBuf::from(path.clone()))?;
···157149158150 let img_bytes = to_resized_image(image.data, 84)?;
159151160160- let value = (date_modified_ms, img_bytes.clone());
161161- write_to_cache(cache_db, &path, value)?;
152152+ if let Some(date_modified_ms) = date_modified_ms {
153153+ let value = (date_modified_ms, img_bytes.clone());
154154+ write_to_cache(cache_db, &path, value)?;
155155+ }
162156163157 Ok(Some(img_bytes.into()))
164158}