[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Invalidate covers on every try

Kasper (Sep 25, 2024, 9:16 AM +0200) 5e7562f4 acc4b3f2

+16 -26
+1 -3
ferrum-addon/addon.d.ts
··· 151 151 export declare function update_playlist(id: string, name: string, description: string): void 152 152 export declare function move_playlist(id: string, fromId: string, toId: string, toIndex: number): void 153 153 /** Returns `None` if the file does not have an image */ 154 - export declare function get_modified_timestamp_ms(path: string): number | null 155 - /** Returns `None` if the file does not have an image */ 156 - export declare function read_cache_cover_async(path: string, index: number, dateModifiedMs: number, cacheDbPath: string): Promise<Buffer | null> 154 + export declare function read_small_cover_async(path: string, index: number, cacheDbPath: string): Promise<Buffer | null> 157 155 export interface TrackMd { 158 156 name: string 159 157 artist: string
+14 -20
src-native/tracks/cover.rs
··· 49 49 } 50 50 51 51 /// Returns `None` if the file does not have an image 52 - #[napi(js_name = "get_modified_timestamp_ms")] 53 - #[allow(dead_code)] 54 - fn get_modified_timestamp_ms_js(path: String) -> Result<Option<i64>> { 55 - let modified_timestamp_ms: i64 = match get_modified_timestamp_ms(&path)? { 56 - Some(modified_timestamp_ms) => modified_timestamp_ms.try_into().unwrap(), 57 - None => return Ok(None), 58 - }; 59 - Ok(Some(modified_timestamp_ms)) 60 - } 61 - 62 52 fn get_modified_timestamp_ms(path: &str) -> Result<Option<u128>> { 63 53 let file_metadata = match fs::metadata(path) { 64 54 Ok(file_metadata) => file_metadata, ··· 124 114 } 125 115 126 116 /// Returns `None` if the file does not have an image 127 - #[napi(js_name = "read_cache_cover_async")] 117 + #[napi(js_name = "read_small_cover_async")] 128 118 #[allow(dead_code)] 129 - pub async fn read_cache_cover_async( 119 + pub async fn read_small_cover_async( 130 120 path: String, 131 121 index: u16, 132 - date_modified_ms: i64, 133 122 cache_db_path: String, 134 123 ) -> Result<Option<Buffer>> { 135 - if date_modified_ms <= 0 { 136 - throw!("date_modified_ms must be greater than 0") 137 - } else if path == "" { 124 + if path == "" { 138 125 throw!("path must not be empty") 139 126 } else if cache_db_path == "" { 140 127 throw!("cache_db_path must not be empty") ··· 145 132 let cache_db_mutex = CACHE_DB.read().unwrap(); 146 133 let cache_db = cache_db_mutex.as_ref().unwrap(); 147 134 148 - if let Some(img_bytes) = get_cached_image(cache_db, &path, date_modified_ms)? { 149 - return Ok(Some(img_bytes.into())); 135 + let date_modified_ms: Option<i64> = 136 + get_modified_timestamp_ms(&path)?.map(|n| n.try_into().unwrap()); 137 + 138 + if let Some(date_modified_ms) = date_modified_ms { 139 + if let Some(img_bytes) = get_cached_image(cache_db, &path, date_modified_ms)? { 140 + return Ok(Some(img_bytes.into())); 141 + } 150 142 } 151 143 152 144 let tag = Tag::read_from_path(&PathBuf::from(path.clone()))?; ··· 157 149 158 150 let img_bytes = to_resized_image(image.data, 84)?; 159 151 160 - let value = (date_modified_ms, img_bytes.clone()); 161 - write_to_cache(cache_db, &path, value)?; 152 + if let Some(date_modified_ms) = date_modified_ms { 153 + let value = (date_modified_ms, img_bytes.clone()); 154 + write_to_cache(cache_db, &path, value)?; 155 + } 162 156 163 157 Ok(Some(img_bytes.into())) 164 158 }
+1 -3
src/electron/main.ts
··· 81 81 const url_raw = new URL(request.url) 82 82 const track_path = decodeURIComponent(url_raw.searchParams.get('path') ?? '') 83 83 const cache_db_path = decodeURIComponent(url_raw.searchParams.get('cache_db_path') ?? '') 84 - const date_modified = decodeURIComponent(url_raw.searchParams.get('date_modified') ?? '') 85 84 86 85 addon 87 - // .read_cache_cover_async(pathname, 0, Number(date_modified), cache_db_path) 88 - .read_cache_cover_async(track_path, 0, parseInt(date_modified), cache_db_path) 86 + .read_small_cover_async(track_path, 0, cache_db_path) 89 87 .then((buffer) => { 90 88 if (buffer === null) { 91 89 resolve(new Response(null, { status: 404 }))