Commit da35256989

da35256989f463e230ed605cb9a54482383fb63e

parent: 5d1367deaf

Unsigned

Vaibhav Mattoo <vaibhavmattoo1@gmail.com> · 2025-08-16 23:45 UTC

fix: overwrite the old cache entry for the channel on a sync command

Layout: unified · split

src/global/structs/subscriptions.rs +21
@@ -235,10 +235,31 @@ fn sync_one(
235235 })]);
236236 }
237237 }
238
239 if let Some(channel) = &channel {
240 let _ = update_channel_cache(channel, image_index);
241 }
238242
239243 Ok((videos, channel))
240244}
241245
246fn update_channel_cache(channel: &FullChannelItem, image_index: usize) -> Result<(), Box<dyn Error>> {
247 let home_dir = home_dir().unwrap();
248 let cache_path = home_dir.join(format!(".cache/youtube-tui/channels/{}.json", channel.id));
249
250 if let Some(parent) = cache_path.parent() {
251 fs::create_dir_all(parent)?;
252 }
253
254 let item = crate::global::structs::Item::from_full_channel(
255 crate::global::traits::SearchProviderWrapper::channel(&channel.id)?,
256 image_index,
257 );
258
259 fs::write(&cache_path, serde_json::to_string(&item)?)?;
260 Ok(())
261}
262
242263#[derive(Clone, Serialize, Deserialize)]
243264pub struct SubItem {
244265 pub channel: FullChannelItem,