Render files as *.json #8

closed
opened by danabra.mov targeting main

Seems nicer in previews

Changed files
+6 -4
src
+6 -4
src/fs.rs
··· 190 .block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) 191 .ok() 192 .flatten() 193 - .map_or(0, |v| serde_json::to_string(&v).unwrap().len()) 194 as u64; 195 let blocks = ((size as u32 + BLKSIZE - 1) / BLKSIZE) as u64; 196 ··· 315 .chain(self.inodes.iter().enumerate().filter_map(|(i, e)| { 316 if let PdsFsEntry::Record(record) = e { 317 if record.parent == ino as usize { 318 - Some((i as u64, record.rkey.clone())) 319 } else { 320 None 321 } ··· 377 } 378 } 379 Some(PdsFsEntry::Collection(_)) => { 380 let record = PdsFsEntry::Record(PdsFsRecord { 381 parent: parent as usize, 382 - rkey: name.to_string_lossy().to_string(), 383 }); 384 if let Some(ino) = self.inodes.get_index_of(&record) { 385 reply.entry(&TTL, &self.attr(ino as u64), 0); ··· 410 let key = format!("{}/{}", col.nsid, r.rkey); 411 412 if let Ok(Some(val)) = rt.block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) { 413 - reply.data(&serde_json::to_string(&val).unwrap().as_bytes()[offset as usize..]); 414 return; 415 } 416 }
··· 190 .block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) 191 .ok() 192 .flatten() 193 + .map_or(0, |v| serde_json::to_string_pretty(&v).unwrap().len()) 194 as u64; 195 let blocks = ((size as u32 + BLKSIZE - 1) / BLKSIZE) as u64; 196 ··· 315 .chain(self.inodes.iter().enumerate().filter_map(|(i, e)| { 316 if let PdsFsEntry::Record(record) = e { 317 if record.parent == ino as usize { 318 + Some((i as u64, format!("{}.json", record.rkey))) 319 } else { 320 None 321 } ··· 377 } 378 } 379 Some(PdsFsEntry::Collection(_)) => { 380 + let name_str = name.to_string_lossy(); 381 + let rkey = name_str.strip_suffix(".json").unwrap_or(&name_str).to_string(); 382 let record = PdsFsEntry::Record(PdsFsRecord { 383 parent: parent as usize, 384 + rkey, 385 }); 386 if let Some(ino) = self.inodes.get_index_of(&record) { 387 reply.entry(&TTL, &self.attr(ino as u64), 0); ··· 412 let key = format!("{}/{}", col.nsid, r.rkey); 413 414 if let Ok(Some(val)) = rt.block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) { 415 + reply.data(&serde_json::to_string_pretty(&val).unwrap().as_bytes()[offset as usize..]); 416 return; 417 } 418 }