[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.

Migrate library version field to string

Kasper (Sep 20, 2024, 6:26 AM +0200) 41d20503 7ac23dd2

+30 -11
+6 -4
Cargo.lock
··· 867 867 868 868 [[package]] 869 869 name = "serde" 870 - version = "1.0.188" 871 - source = "git+https://github.com/Astavie/serde?rev=f552a790e985f9e9cd6a09ec909f0f8091ac1525#f552a790e985f9e9cd6a09ec909f0f8091ac1525" 870 + version = "1.0.210" 871 + source = "registry+https://github.com/rust-lang/crates.io-index" 872 + checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" 872 873 dependencies = [ 873 874 "serde_derive", 874 875 ] 875 876 876 877 [[package]] 877 878 name = "serde_derive" 878 - version = "1.0.188" 879 - source = "git+https://github.com/Astavie/serde?rev=f552a790e985f9e9cd6a09ec909f0f8091ac1525#f552a790e985f9e9cd6a09ec909f0f8091ac1525" 879 + version = "1.0.210" 880 + source = "registry+https://github.com/rust-lang/crates.io-index" 881 + checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" 880 882 dependencies = [ 881 883 "proc-macro2", 882 884 "quote",
-4
Cargo.toml
··· 34 34 unicode-normalization = "0.1" 35 35 rayon = "1.8" 36 36 37 - [patch.crates-io] 38 - # For allowing integer version field in Library.json (https://github.com/serde-rs/serde/pull/2525) 39 - serde = { git = "https://github.com/Astavie/serde", rev = "f552a790e985f9e9cd6a09ec909f0f8091ac1525" } 40 - 41 37 [profile.dev] 42 38 panic = "abort" 43 39
+22 -1
src-native/library.rs
··· 1 1 use crate::library_types::{Library, VersionedLibrary}; 2 2 use crate::UniResult; 3 3 use serde::{Deserialize, Serialize}; 4 + use serde_json::{json, Value}; 4 5 use std::fs::{create_dir_all, File}; 5 6 use std::io::{Error, ErrorKind, Read}; 6 7 use std::path::PathBuf; ··· 44 45 println!("Read library: {}ms", now.elapsed().as_millis()); 45 46 now = Instant::now(); 46 47 47 - let versioned_library: VersionedLibrary = match serde_json::from_str(&mut json_str) { 48 + let mut value: Value = match serde_json::from_str(&mut json_str) { 49 + Ok(library) => library, 50 + Err(err) => throw!("Error parsing library file: {:?}", err), 51 + }; 52 + // Migrate version number to string 53 + println!("---- PARSE LIBRARY"); 54 + if let Some(obj) = value.as_object_mut() { 55 + println!("---- ob"); 56 + if let Some(version_field) = obj.get_mut("version") { 57 + println!("---- ve"); 58 + if let Some(version) = version_field.as_number() { 59 + if version.as_u64() == Some(1) { 60 + *version_field = json!("1"); 61 + } else if version.as_u64() == Some(2) { 62 + *version_field = json!("2"); 63 + } 64 + } 65 + } 66 + } 67 + 68 + let versioned_library: VersionedLibrary = match serde_json::from_value(value) { 48 69 Ok(library) => library, 49 70 Err(err) => throw!("Error parsing library file: {:?}", err), 50 71 };
+2 -2
src-native/library_types.rs
··· 26 26 #[derive(Serialize, Deserialize, Clone, Debug)] 27 27 #[serde(tag = "version", deny_unknown_fields)] 28 28 pub enum VersionedLibrary<'a> { 29 - #[serde(rename = 1)] 29 + #[serde(rename = "1")] 30 30 V1(Cow<'a, V1Library>), 31 - #[serde(rename = 2)] 31 + #[serde(rename = "2")] 32 32 V2(Cow<'a, Library>), 33 33 } 34 34 impl VersionedLibrary<'_> {