guidelumineux@fairytail01:~$ cd "$HOME/Bibliotheca-Test/bibliotheca-app" python3 - <<'PY' from pathlib import Path p = Path("src-tauri/src/lib.rs") lines = p.read_text(encoding="utf-8").splitlines() terms = [ "struct StorageRootsState", "struct ResolvedStorageRoot", "struct StorageRootEntry", "fn initialize_storage_roots", "tauri::Builder", "invoke_handler", "generate_handler!", "#[tauri::command]", ] found = set() for term in terms: for i, line in enumerate(lines): if term in line: start, end = max(0, i-8), min(len(lines), i+35) PY print(f"{n+1}: {lines[n]}") {start+1} à {end} =====") ===== struct StorageRootsState — lignes 48 à 90 ===== 48: id: String, 49: root_type: String, 50: label: String, 51: path: PathBuf, 52: available: bool, 53: } 54: 55: #[allow(dead_code)] 56: struct StorageRootsState { 57: config_path: PathBuf, 58: roots: Vec, 59: } 60: 61: fn ensure_storage_directory(path: &Path) -> Result<(), String> { 62: let absolute = if path.is_absolute() { 63: path.to_path_buf() 64: } else { 65: std::env::current_dir() 66: .map_err(|error| format!("Lecture du dossier courant impossible : {error}"))? 67: .join(path) 68: }; 69: 70: let mut current = PathBuf::new(); 71: 72: for component in absolute.components() { 73: match component { 74: std::path::Component::Prefix(prefix) => current.push(prefix.as_os_str()), 75: std::path::Component::RootDir => current.push(component.as_os_str()), 76: std::path::Component::CurDir => {} 77: std::path::Component::ParentDir => { 78: return Err(format!( 79: "Un chemin de stockage contenant '..' est refusé : {}", 80: path.display() 81: )); 82: } 83: std::path::Component::Normal(name) => { 84: current.push(name); 85: 86: match std::fs::symlink_metadata(¤t) { 87: Ok(metadata) => { 88: if metadata.file_type().is_symlink() { 89: return Err(format!( 90: "Lien symbolique refusé dans le chemin de stockage : {}", ===== fn initialize_storage_roots — lignes 300 à 342 ===== 300: if result.is_err() { 301: // Ne retirer que le fichier créé par cette tentative. 302: let _ = std::fs::remove_file(path); 303: } 304: 305: result 306: } 307: 308: fn initialize_storage_roots(test_root: &Path) -> Result { 309: let configuration_dir = test_root.join("configuration"); 310: ensure_storage_directory(&configuration_dir)?; 311: 312: let config_path = configuration_dir.join("storage-roots.json"); 313: 314: match std::fs::symlink_metadata(&config_path) { 315: Ok(metadata) => { 316: if metadata.file_type().is_symlink() || !metadata.is_file() { 317: return Err("Le fichier storage-roots.json n'est pas un fichier ordinaire.".into()); 318: } 319: } 320: Err(error) if error.kind() == std::io::ErrorKind::NotFound => { 321: write_initial_storage_roots_config(&config_path)?; 322: } 323: Err(error) => { 324: return Err(format!( 325: "Inspection de storage-roots.json impossible : {error}" 326: )); 327: } 328: } 329: 330: let content = std::fs::read_to_string(&config_path) 331: .map_err(|error| format!("Lecture de storage-roots.json impossible : {error}"))?; 332: 333: let document: StorageRootsDocument = serde_json::from_str(&content) 334: .map_err(|error| format!("Configuration des racines invalide : {error}"))?; 335: 336: validate_storage_roots_document(&document)?; 337: 338: let mut resolved_roots = Vec::with_capacity(document.roots.len()); 339: 340: for root in document.roots { 341: let (resolved_path, available) = match root.root_type.as_str() { 342: "managed" => { ===== tauri::Builder — lignes 7440 à 7482 ===== 7440: name: clean_name.to_string(), 7441: uuid: library_uuid, 7442: path: final_path.to_string_lossy().into_owned(), 7443: }) 7444: } 7445: 7446: #[cfg_attr(mobile, tauri::mobile_entry_point)] 7447: pub fn run() { 7448: tauri::Builder::default() 7449: .plugin(tauri_plugin_dialog::init()) 7450: .plugin(tauri_plugin_opener::init()) 7451: .setup(|app| { 7452: let home = app.path().home_dir()?; 7453: let test_root = match std::env::var_os("BIBLIOTHECA_TEST_ROOT") { 7454: Some(path) => std::path::PathBuf::from(path), 7455: None => home.join("Bibliotheca-Test"), 7456: }; 7457: let database_dir = test_root.join("database"); 7458: 7459: std::fs::create_dir_all(&database_dir)?; 7460: 7461: let database_path = database_dir.join("bibliotheca.sqlite3"); 7462: let connection = Connection::open(&database_path)?; 7463: 7464: connection.execute_batch("PRAGMA foreign_keys = ON;")?; 7465: 7466: let schema_version = initialize_database(&connection).map_err(std::io::Error::other)?; 7467: 7468: println!( 7469: "Bibliotheca SQLite initialisée : {} (schéma {})", 7470: database_path.display(), 7471: schema_version 7472: ); 7473: 7474: app.manage(Database { 7475: connection: Mutex::new(connection), 7476: path: database_path, 7477: }); 7478: 7479: let associations_path = test_root.join("associations-fichiers.json"); 7480: let downloads_path = test_root.join("Téléchargements"); 7481: 7482: let storage_roots = ===== invoke_handler — lignes 7486 à 7528 ===== 7486: path: associations_path, 7487: downloads_path, 7488: lock: Mutex::new(()), 7489: }); 7490: 7491: app.manage(storage_roots); 7492: Ok(()) 7493: }) 7494: .invoke_handler(tauri::generate_handler![ 7495: greet, 7496: database_status, 7497: list_works, 7498: list_advanced_search_families, 7499: run_advanced_search, 7500: list_tags, 7501: list_all_tags, 7502: add_or_reactivate_tag, 7503: retire_tag, 7504: list_secondary_tags, 7505: list_all_secondary_tags, 7506: add_or_reactivate_secondary_tag, 7507: retire_secondary_tag, 7508: list_erotic_tags, 7509: list_all_erotic_tags, 7510: add_or_reactivate_erotic_tag, 7511: retire_erotic_tag, 7512: list_genres, 7513: list_all_genres, 7514: add_or_reactivate_genre, 7515: retire_genre, 7516: list_demographics, 7517: list_all_demographics, 7518: add_or_reactivate_demographic, 7519: retire_demographic, 7520: list_relation_types, 7521: list_editorial_forms, 7522: list_erotic_tag_forms, 7523: list_editorial_subforms, 7524: list_original_languages, 7525: list_publisher_types, 7526: list_work_statuses, 7527: list_link_types, 7528: add_or_reactivate_link_type, ===== #[tauri::command] — lignes 687 à 729 ===== 687: return Err(format!( 688: "La limite ne peut pas être inférieure aux {current_count} associations déjà présentes." 689: )); 690: } 691: 692: Ok(()) 693: } 694: 695: #[tauri::command] 696: fn get_work_file_limit_status( 697: work_id: i64, 698: database: State<'_, Database>, 699: associations: State<'_, FileAssociationsState>, 700: ) -> Result { 701: let connection = database 702: .connection 703: .lock() 704: .map_err(|error| error.to_string())?; 705: 706: let form: String = connection 707: .query_row( 708: "SELECT editorial_form FROM works WHERE id = ?1", 709: [work_id], 710: |row| row.get(0), 711: ) 712: .map_err(|error| { 713: if matches!(error, rusqlite::Error::QueryReturnedNoRows) { 714: "Cette œuvre n'existe pas.".to_string() 715: } else { 716: error.to_string() 717: } 718: })?; 719: 720: let _guard = associations 721: .lock 722: .lock() 723: .map_err(|error| error.to_string())?; 724: 725: let association_document = read_file_associations(&associations.path)?; 726: 727: make_work_file_limit_status(&connection, &form, work_id, &association_document) 728: } 729: ===== #[tauri::command] — lignes 864 à 906 ===== 864: let _ = std::fs::remove_file(&destination); 865: return Err(error); 866: } 867: 868: return Ok(candidate_name); 869: } 870: } 871: 872: #[tauri::command] 873: fn list_work_files( 874: work_id: i64, 875: database: State<'_, Database>, 876: associations: State<'_, FileAssociationsState>, 877: ) -> Result, String> { 878: let connection = database 879: .connection 880: .lock() 881: .map_err(|error| error.to_string())?; 882: 883: let exists: bool = connection 884: .query_row( 885: "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", 886: [work_id], 887: |row| row.get(0), 888: ) 889: .map_err(|error| error.to_string())?; 890: 891: if !exists { 892: return Err("Cette œuvre n'existe pas.".into()); 893: } 894: 895: let _guard = associations 896: .lock 897: .lock() 898: .map_err(|error| error.to_string())?; 899: 900: let document = read_file_associations(&associations.path)?; 901: 902: Ok(document 903: .associations 904: .iter() 905: .filter(|association| association.work_id == work_id && association.unit_id.is_none()) 906: .map(|association| WorkFile { ===== #[tauri::command] — lignes 909 à 951 ===== 909: .file_name() 910: .and_then(|name| name.to_str()) 911: .unwrap_or(&association.file) 912: .to_string(), 913: }) 914: .collect()) 915: } 916: 917: #[tauri::command] 918: fn list_reader_file_availability( 919: associations: State<'_, FileAssociationsState>, 920: ) -> Result, String> { 921: let _guard = associations 922: .lock 923: .lock() 924: .map_err(|error| error.to_string())?; 925: 926: let document = read_file_associations(&associations.path)?; 927: 928: let mut result = Vec::with_capacity(document.associations.len()); 929: 930: for association in &document.associations { 931: let path = Path::new(&association.file); 932: 933: let original_filename = path 934: .file_name() 935: .and_then(|name| name.to_str()) 936: .unwrap_or(&association.file) 937: .to_string(); 938: 939: let extension = path 940: .extension() 941: .and_then(|value| value.to_str()) 942: .map(str::to_ascii_lowercase); 943: 944: let (accessible, status) = match std::fs::metadata(path) { 945: Ok(metadata) if !metadata.is_file() => (false, "not_file"), 946: Ok(_) => match std::fs::File::open(path) { 947: Ok(_) => (true, "accessible"), 948: Err(_) => (false, "inaccessible"), 949: }, 950: Err(error) if error.kind() == std::io::ErrorKind::NotFound => (false, "missing"), 951: Err(_) => (false, "inaccessible"), ===== #[tauri::command] — lignes 1022 à 1064 ===== 1022: 1023: if !matches!(extension.as_str(), "zip" | "cbz") { 1024: return Err("Cette association ne désigne pas une archive ZIP ou CBZ.".into()); 1025: } 1026: 1027: Ok(path) 1028: } 1029: 1030: #[tauri::command] 1031: fn read_reader_file( 1032: association_id: i64, 1033: associations: State<'_, FileAssociationsState>, 1034: ) -> Result { 1035: let path = reader_association_path(&associations, association_id)?; 1036: 1037: if reader_image_extension( 1038: path.file_name() 1039: .and_then(|name| name.to_str()) 1040: .unwrap_or(""), 1041: ) 1042: .is_none() 1043: { 1044: return Err("Format d'image non pris en charge.".into()); 1045: } 1046: 1047: let file = std::fs::File::open(&path) 1048: .map_err(|error| format!("Ouverture du fichier impossible : {error}"))?; 1049: 1050: let metadata = file.metadata().map_err(|error| error.to_string())?; 1051: 1052: if !metadata.is_file() { 1053: return Err("L'association ne désigne pas un fichier ordinaire.".into()); 1054: } 1055: 1056: if metadata.len() > READER_MAX_IMAGE_BYTES { 1057: return Err("Image trop volumineuse (limite : 64 Mio).".into()); 1058: } 1059: 1060: let mut bytes = Vec::with_capacity(metadata.len() as usize); 1061: let mut limited = file.take(READER_MAX_IMAGE_BYTES + 1); 1062: 1063: limited 1064: .read_to_end(&mut bytes) ===== #[tauri::command] — lignes 1066 à 1108 ===== 1066: 1067: if bytes.len() as u64 > READER_MAX_IMAGE_BYTES { 1068: return Err("Image trop volumineuse (limite : 64 Mio).".into()); 1069: } 1070: 1071: Ok(Response::new(bytes)) 1072: } 1073: 1074: #[tauri::command] 1075: fn list_reader_archive_entries( 1076: association_id: i64, 1077: associations: State<'_, FileAssociationsState>, 1078: ) -> Result, String> { 1079: let path = reader_archive_path(&associations, association_id)?; 1080: 1081: let file = std::fs::File::open(&path) 1082: .map_err(|error| format!("Ouverture de l'archive impossible : {error}"))?; 1083: 1084: let mut archive = zip::ZipArchive::new(file) 1085: .map_err(|error| format!("Archive ZIP/CBZ invalide : {error}"))?; 1086: 1087: if archive.len() > READER_MAX_ARCHIVE_ENTRIES { 1088: return Err("Archive trop volumineuse en nombre d'entrées.".into()); 1089: } 1090: 1091: let mut result = Vec::new(); 1092: 1093: for entry_index in 0..archive.len() { 1094: let entry = archive 1095: .by_index(entry_index) 1096: .map_err(|error| format!("Lecture de l'index ZIP impossible : {error}"))?; 1097: 1098: if !entry.is_file() { 1099: continue; 1100: } 1101: 1102: let name = entry 1103: .name() 1104: .map_err(|error| format!("Nom d'entrée ZIP invalide : {error}"))? 1105: .into_owned(); 1106: 1107: let Some(extension) = reader_image_extension(&name) else { 1108: continue; ===== #[tauri::command] — lignes 1117 à 1159 ===== 1117: size_bytes, 1118: readable: size_bytes <= READER_MAX_IMAGE_BYTES, 1119: }); 1120: } 1121: 1122: Ok(result) 1123: } 1124: 1125: #[tauri::command] 1126: fn read_reader_archive_entry( 1127: association_id: i64, 1128: entry_index: usize, 1129: associations: State<'_, FileAssociationsState>, 1130: ) -> Result { 1131: let path = reader_archive_path(&associations, association_id)?; 1132: 1133: let file = std::fs::File::open(&path) 1134: .map_err(|error| format!("Ouverture de l'archive impossible : {error}"))?; 1135: 1136: let mut archive = zip::ZipArchive::new(file) 1137: .map_err(|error| format!("Archive ZIP/CBZ invalide : {error}"))?; 1138: 1139: if entry_index >= archive.len() { 1140: return Err("Index de page hors limites.".into()); 1141: } 1142: 1143: let entry = archive 1144: .by_index(entry_index) 1145: .map_err(|error| format!("Lecture de la page impossible : {error}"))?; 1146: 1147: if !entry.is_file() { 1148: return Err("Cette entrée ZIP n'est pas un fichier.".into()); 1149: } 1150: 1151: let name = entry 1152: .name() 1153: .map_err(|error| format!("Nom d'entrée ZIP invalide : {error}"))?; 1154: 1155: if reader_image_extension(name.as_ref()).is_none() { 1156: return Err("Cette entrée n'est pas une image prise en charge.".into()); 1157: } 1158: 1159: if entry.size() > READER_MAX_IMAGE_BYTES { ===== #[tauri::command] — lignes 1211 à 1253 ===== 1211: return Err( 1212: "Cette unité est retirée et ne peut plus recevoir de nouveaux fichiers.".into(), 1213: ); 1214: } 1215: 1216: Ok(unit_id) 1217: } 1218: 1219: #[tauri::command] 1220: fn add_file_associations( 1221: work_id: i64, 1222: unit_id: Option, 1223: file_paths: Vec, 1224: database: State<'_, Database>, 1225: associations: State<'_, FileAssociationsState>, 1226: ) -> Result, String> { 1227: if file_paths.is_empty() { 1228: return Ok(Vec::new()); 1229: } 1230: 1231: let connection = database 1232: .connection 1233: .lock() 1234: .map_err(|error| error.to_string())?; 1235: 1236: let exists: bool = connection 1237: .query_row( 1238: "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", 1239: [work_id], 1240: |row| row.get(0), 1241: ) 1242: .map_err(|error| error.to_string())?; 1243: 1244: if !exists { 1245: return Err("Cette œuvre n'existe pas.".into()); 1246: } 1247: 1248: let unit_id = validate_file_association_unit(&connection, work_id, unit_id)?; 1249: 1250: let mut validated_paths = Vec::new(); 1251: 1252: for file_path in file_paths { 1253: let source = PathBuf::from(&file_path); ===== #[tauri::command] — lignes 1323 à 1365 ===== 1323: added_ids.push(next_id); 1324: } 1325: 1326: write_file_associations(&associations.path, &document)?; 1327: 1328: Ok(added_ids) 1329: } 1330: 1331: #[tauri::command] 1332: fn remove_file_association( 1333: association_id: i64, 1334: associations: State<'_, FileAssociationsState>, 1335: ) -> Result<(), String> { 1336: let _guard = associations 1337: .lock 1338: .lock() 1339: .map_err(|error| error.to_string())?; 1340: 1341: let mut document = read_file_associations(&associations.path)?; 1342: let previous_len = document.associations.len(); 1343: 1344: document 1345: .associations 1346: .retain(|association| association.id != association_id); 1347: 1348: if document.associations.len() == previous_len { 1349: return Err("Association introuvable.".into()); 1350: } 1351: 1352: write_file_associations(&associations.path, &document) 1353: } 1354: 1355: #[tauri::command] 1356: fn remove_all_file_associations( 1357: work_id: i64, 1358: database: State<'_, Database>, 1359: associations: State<'_, FileAssociationsState>, 1360: ) -> Result { 1361: remove_all_file_associations_internal(work_id, &database, &associations) 1362: } 1363: 1364: fn remove_all_file_associations_internal( 1365: work_id: i64, ===== #[tauri::command] — lignes 1401 à 1443 ===== 1401: 1402: if removed > 0 { 1403: write_file_associations(&associations.path, &document)?; 1404: } 1405: 1406: Ok(removed) 1407: } 1408: 1409: #[tauri::command] 1410: fn copy_associated_file( 1411: association_id: i64, 1412: associations: State<'_, FileAssociationsState>, 1413: ) -> Result { 1414: let source_path = { 1415: let _guard = associations 1416: .lock 1417: .lock() 1418: .map_err(|error| error.to_string())?; 1419: 1420: let document = read_file_associations(&associations.path)?; 1421: 1422: document 1423: .associations 1424: .iter() 1425: .find(|association| association.id == association_id) 1426: .map(|association| PathBuf::from(&association.file)) 1427: .ok_or_else(|| "Association introuvable.".to_string())? 1428: }; 1429: 1430: let downloads = associations.downloads_path.clone(); 1431: 1432: copy_file_without_overwriting(&source_path, &downloads) 1433: } 1434: 1435: #[derive(Serialize)] 1436: #[serde(rename_all = "camelCase")] 1437: struct BulkDownloadReport { 1438: copied_files: usize, 1439: missing_files: Vec, 1440: errors: Vec, 1441: output_folders: Vec, 1442: } 1443: ===== #[tauri::command] — lignes 1534 à 1576 ===== 1534: )); 1535: } 1536: } 1537: } 1538: 1539: unreachable!() 1540: } 1541: 1542: #[tauri::command] 1543: fn download_associated_files( 1544: work_ids: Vec, 1545: unit_ids: Vec, 1546: destination_dir: String, 1547: global_batch: bool, 1548: batch_folder_name: Option, 1549: database: State<'_, Database>, 1550: associations: State<'_, FileAssociationsState>, 1551: ) -> Result { 1552: download_associated_files_internal( 1553: work_ids, 1554: unit_ids, 1555: destination_dir, 1556: global_batch, 1557: batch_folder_name, 1558: &database, 1559: &associations, 1560: ) 1561: } 1562: 1563: fn download_associated_files_internal( 1564: work_ids: Vec, 1565: unit_ids: Vec, 1566: destination_dir: String, 1567: global_batch: bool, 1568: batch_folder_name: Option, 1569: database: &Database, 1570: associations: &FileAssociationsState, 1571: ) -> Result { 1572: if work_ids.is_empty() && unit_ids.is_empty() { 1573: return Err("Aucune œuvre ou unité sélectionnée.".into()); 1574: } 1575: 1576: let destination = PathBuf::from(destination_dir); ===== #[tauri::command] — lignes 1910 à 1952 ===== 1910: Ok(BulkDownloadReport { 1911: copied_files, 1912: missing_files, 1913: errors, 1914: output_folders, 1915: }) 1916: } 1917: 1918: #[tauri::command] 1919: fn download_selected_associated_files( 1920: work_id: i64, 1921: association_ids: Vec, 1922: destination_dir: String, 1923: database: State<'_, Database>, 1924: associations: State<'_, FileAssociationsState>, 1925: ) -> Result { 1926: download_selected_associated_files_internal( 1927: work_id, 1928: association_ids, 1929: destination_dir, 1930: &database, 1931: &associations, 1932: ) 1933: } 1934: 1935: fn download_selected_associated_files_internal( 1936: work_id: i64, 1937: association_ids: Vec, 1938: destination_dir: String, 1939: database: &Database, 1940: associations: &FileAssociationsState, 1941: ) -> Result { 1942: if association_ids.is_empty() { 1943: return Err("Aucun fichier n'est sélectionné.".into()); 1944: } 1945: 1946: let selected_ids: HashSet = association_ids.iter().copied().collect(); 1947: 1948: if selected_ids.len() != association_ids.len() { 1949: return Err("La sélection contient des identifiants en double.".into()); 1950: } 1951: 1952: // Lire les associations sous le verrou, sans modifier le JSON. ===== #[tauri::command] — lignes 2544 à 2586 ===== 2544: .to_lowercase() 2545: .cmp(&b.label.to_lowercase()) 2546: .then_with(|| a.title.to_lowercase().cmp(&b.title.to_lowercase())) 2547: }); 2548: 2549: Ok(relations) 2550: } 2551: 2552: #[tauri::command] 2553: fn greet(name: &str) -> String { 2554: format!("Hello, {}! You've been greeted from Rust!", name) 2555: } 2556: 2557: #[tauri::command] 2558: fn database_status(database: State<'_, Database>) -> Result { 2559: let connection = database 2560: .connection 2561: .lock() 2562: .map_err(|error| error.to_string())?; 2563: 2564: let schema_version = connection 2565: .query_row("PRAGMA user_version", [], |row| row.get(0)) 2566: .map_err(|error| error.to_string())?; 2567: 2568: let works_count = connection 2569: .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) 2570: .map_err(|error| error.to_string())?; 2571: 2572: Ok(DatabaseStatus { 2573: path: database.path.to_string_lossy().into_owned(), 2574: schema_version, 2575: works_count, 2576: }) 2577: } 2578: 2579: #[derive(Debug, Serialize)] 2580: #[serde(rename_all = "camelCase")] 2581: struct AdvancedSearchFamily { 2582: key: String, 2583: label: String, 2584: value_kind: String, 2585: } 2586: ===== #[tauri::command] — lignes 2927 à 2969 ===== 2927: Expression::OrNot(left, right) => Ok(format!( 2928: "({} OR NOT {})", 2929: advanced_search_expression_sql(connection, left, values)?, 2930: advanced_search_expression_sql(connection, right, values)? 2931: )), 2932: } 2933: } 2934: 2935: #[tauri::command] 2936: fn run_advanced_search( 2937: expression: String, 2938: database: State<'_, Database>, 2939: ) -> Result, String> { 2940: let parsed = advanced_search::parse_expression(&expression)?; 2941: let connection = database 2942: .connection 2943: .lock() 2944: .map_err(|error| error.to_string())?; 2945: 2946: let mut values = Vec::new(); 2947: let predicate = advanced_search_expression_sql(&connection, &parsed, &mut values)?; 2948: let sql = format!( 2949: "SELECT w.id 2950: FROM works w 2951: WHERE NOT EXISTS ( 2952: SELECT 1 FROM work_suppressions ws 2953: WHERE ws.work_uuid = w.portable_uuid 2954: ) 2955: AND ({predicate}) 2956: ORDER BY COALESCE(NULLIF(w.title_english, ''), w.title_original) 2957: COLLATE NOCASE" 2958: ); 2959: 2960: let mut statement = connection 2961: .prepare(&sql) 2962: .map_err(|error| error.to_string())?; 2963: let rows = statement 2964: .query_map(params_from_iter(values.iter()), |row| row.get::<_, i64>(0)) 2965: .map_err(|error| error.to_string())?; 2966: 2967: rows.collect::, _>>() 2968: .map_err(|error| error.to_string()) 2969: } ===== #[tauri::command] — lignes 3460 à 3502 ===== 3460: transaction 3461: .execute(association_sql, params![work_id, id]) 3462: .map_err(|error| error.to_string())?; 3463: } 3464: 3465: Ok(()) 3466: } 3467: 3468: #[tauri::command] 3469: fn create_work(input: CreateWorkInput, database: State<'_, Database>) -> Result { 3470: let mut connection = database 3471: .connection 3472: .lock() 3473: .map_err(|error| error.to_string())?; 3474: 3475: let relation_types = load_relation_types(&connection)?; 3476: create_work_with_relation_types(&mut connection, input, &relation_types) 3477: } 3478: 3479: // Wrapper conservé pour les tests historiques. 3480: fn create_work_with_connection( 3481: connection: &mut Connection, 3482: input: CreateWorkInput, 3483: ) -> Result { 3484: let relation_types = load_relation_types(connection)?; 3485: create_work_with_relation_types(connection, input, &relation_types) 3486: } 3487: 3488: fn resolve_catalog_key( 3489: connection: &Connection, 3490: table: &str, 3491: key_column: &str, 3492: label_column: &str, 3493: value: &str, 3494: family_label: &str, 3495: ) -> Result { 3496: // Les identifiants SQL proviennent exclusivement des appels internes. 3497: let sql = format!( 3498: "SELECT {key_column} FROM {table} 3499: WHERE ({key_column} = ?1 OR {label_column} = ?1) 3500: AND is_available = 1" 3501: ); 3502: ===== #[tauri::command] — lignes 3909 à 3951 ===== 3909: ) 3910: .map_err(|error| error.to_string())?; 3911: } 3912: 3913: transaction.commit().map_err(|error| error.to_string())?; 3914: Ok(work_id) 3915: } 3916: 3917: #[tauri::command] 3918: fn list_tags(database: State<'_, Database>) -> Result, String> { 3919: let connection = database 3920: .connection 3921: .lock() 3922: .map_err(|error| error.to_string())?; 3923: 3924: let mut statement = connection 3925: .prepare("SELECT name FROM tags WHERE is_available = 1 ORDER BY name COLLATE NOCASE") 3926: .map_err(|error| error.to_string())?; 3927: 3928: let rows = statement 3929: .query_map([], |row| row.get::<_, String>(0)) 3930: .map_err(|error| error.to_string())?; 3931: 3932: rows.collect::, _>>() 3933: .map_err(|error| error.to_string()) 3934: } 3935: 3936: #[tauri::command] 3937: fn list_all_tags(database: State<'_, Database>) -> Result, String> { 3938: let connection = database 3939: .connection 3940: .lock() 3941: .map_err(|error| error.to_string())?; 3942: 3943: let mut statement = connection 3944: .prepare( 3945: "SELECT name, is_available FROM tags 3946: ORDER BY is_available DESC, name COLLATE NOCASE", 3947: ) 3948: .map_err(|error| error.to_string())?; 3949: 3950: let rows = statement 3951: .query_map([], |row| { ===== #[tauri::command] — lignes 3955 à 3997 ===== 3955: }) 3956: }) 3957: .map_err(|error| error.to_string())?; 3958: 3959: rows.collect::, _>>() 3960: .map_err(|error| error.to_string()) 3961: } 3962: 3963: #[tauri::command] 3964: fn add_or_reactivate_tag(name: String, database: State<'_, Database>) -> Result<(), String> { 3965: let name = name.trim(); 3966: 3967: if name.is_empty() { 3968: return Err("Le nom du tag ne peut pas être vide.".to_string()); 3969: } 3970: 3971: let connection = database 3972: .connection 3973: .lock() 3974: .map_err(|error| error.to_string())?; 3975: 3976: connection 3977: .execute("INSERT OR IGNORE INTO tags(name) VALUES (?1)", [name]) 3978: .map_err(|error| error.to_string())?; 3979: 3980: connection 3981: .execute("UPDATE tags SET is_available = 1 WHERE name = ?1", [name]) 3982: .map_err(|error| error.to_string())?; 3983: 3984: Ok(()) 3985: } 3986: 3987: #[tauri::command] 3988: fn retire_tag(name: String, database: State<'_, Database>) -> Result<(), String> { 3989: let connection = database 3990: .connection 3991: .lock() 3992: .map_err(|error| error.to_string())?; 3993: 3994: let changed = connection 3995: .execute( 3996: "UPDATE tags SET is_available = 0 WHERE name = ?1", 3997: [name.trim()], ===== #[tauri::command] — lignes 4102 à 4144 ===== 4102: 4103: if changed == 0 { 4104: return Err("Tag introuvable.".to_string()); 4105: } 4106: 4107: Ok(()) 4108: } 4109: 4110: #[tauri::command] 4111: fn list_secondary_tags(database: State<'_, Database>) -> Result, String> { 4112: let connection = database 4113: .connection 4114: .lock() 4115: .map_err(|error| error.to_string())?; 4116: 4117: Ok( 4118: list_catalog_tags_with_connection(&connection, "secondary_tags", false)? 4119: .into_iter() 4120: .map(|entry| entry.name) 4121: .collect(), 4122: ) 4123: } 4124: 4125: #[tauri::command] 4126: fn list_all_secondary_tags( 4127: database: State<'_, Database>, 4128: ) -> Result, String> { 4129: let connection = database 4130: .connection 4131: .lock() 4132: .map_err(|error| error.to_string())?; 4133: 4134: list_catalog_tags_with_connection(&connection, "secondary_tags", true) 4135: } 4136: 4137: #[tauri::command] 4138: fn add_or_reactivate_secondary_tag( 4139: name: String, 4140: database: State<'_, Database>, 4141: ) -> Result<(), String> { 4142: let connection = database 4143: .connection 4144: .lock() ===== #[tauri::command] — lignes 4152 à 4194 ===== 4152: let connection = database 4153: .connection 4154: .lock() 4155: .map_err(|error| error.to_string())?; 4156: 4157: retire_catalog_tag_with_connection(&connection, "secondary_tags", &name) 4158: } 4159: 4160: #[tauri::command] 4161: fn list_erotic_tags(database: State<'_, Database>) -> Result, String> { 4162: let connection = database 4163: .connection 4164: .lock() 4165: .map_err(|error| error.to_string())?; 4166: 4167: Ok( 4168: list_catalog_tags_with_connection(&connection, "erotic_tags", false)? 4169: .into_iter() 4170: .map(|entry| entry.name) 4171: .collect(), 4172: ) 4173: } 4174: 4175: #[tauri::command] 4176: fn list_all_erotic_tags(database: State<'_, Database>) -> Result, String> { 4177: let connection = database 4178: .connection 4179: .lock() 4180: .map_err(|error| error.to_string())?; 4181: 4182: list_catalog_tags_with_connection(&connection, "erotic_tags", true) 4183: } 4184: 4185: #[tauri::command] 4186: fn add_or_reactivate_erotic_tag(name: String, database: State<'_, Database>) -> Result<(), String> { 4187: let connection = database 4188: .connection 4189: .lock() 4190: .map_err(|error| error.to_string())?; 4191: 4192: add_or_reactivate_catalog_tag_with_connection(&connection, "erotic_tags", &name) 4193: } 4194: ===== #[tauri::command] — lignes 4197 à 4239 ===== 4197: let connection = database 4198: .connection 4199: .lock() 4200: .map_err(|error| error.to_string())?; 4201: 4202: retire_catalog_tag_with_connection(&connection, "erotic_tags", &name) 4203: } 4204: 4205: #[tauri::command] 4206: fn list_work_units( 4207: work_id: i64, 4208: database: State<'_, Database>, 4209: associations: State<'_, FileAssociationsState>, 4210: ) -> Result, String> { 4211: let connection = database 4212: .connection 4213: .lock() 4214: .map_err(|error| error.to_string())?; 4215: 4216: let exists: bool = connection 4217: .query_row( 4218: "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", 4219: [work_id], 4220: |row| row.get(0), 4221: ) 4222: .map_err(|error| error.to_string())?; 4223: 4224: if !exists { 4225: return Err("Cette œuvre n'existe pas.".to_string()); 4226: } 4227: 4228: let _guard = associations 4229: .lock 4230: .lock() 4231: .map_err(|error| error.to_string())?; 4232: 4233: let document = read_file_associations(&associations.path)?; 4234: 4235: let units = { 4236: let mut statement = connection 4237: .prepare( 4238: "SELECT id, work_id, parent_unit_id, unit_type, 4239: label, sort_order, created_at, updated_at, is_retired ===== #[tauri::command] — lignes 4295 à 4337 ===== 4295: is_retired: unit.8, 4296: files, 4297: }); 4298: } 4299: 4300: Ok(result) 4301: } 4302: 4303: #[tauri::command] 4304: fn create_work_unit( 4305: work_id: i64, 4306: parent_unit_id: Option, 4307: unit_type: String, 4308: label: String, 4309: sort_order: i64, 4310: database: State<'_, Database>, 4311: ) -> Result { 4312: let connection = database 4313: .connection 4314: .lock() 4315: .map_err(|error| error.to_string())?; 4316: 4317: create_work_unit_with_connection( 4318: &connection, 4319: work_id, 4320: parent_unit_id, 4321: unit_type, 4322: label, 4323: sort_order, 4324: ) 4325: } 4326: 4327: fn set_work_unit_retired_with_connection( 4328: connection: &Connection, 4329: work_id: i64, 4330: unit_id: i64, 4331: retired: bool, 4332: ) -> Result<(), String> { 4333: let exists: bool = connection 4334: .query_row( 4335: "SELECT EXISTS( 4336: SELECT 1 FROM work_units 4337: WHERE id = ?1 ===== #[tauri::command] — lignes 4390 à 4432 ===== 4390: AND is_retired != ?1", 4391: rusqlite::params![retired, work_id], 4392: ) 4393: .map_err(|error| error.to_string())?; 4394: 4395: Ok(changed) 4396: } 4397: 4398: #[tauri::command] 4399: fn set_work_unit_retired( 4400: work_id: i64, 4401: unit_id: i64, 4402: retired: bool, 4403: database: State<'_, Database>, 4404: ) -> Result<(), String> { 4405: let connection = database 4406: .connection 4407: .lock() 4408: .map_err(|error| error.to_string())?; 4409: 4410: set_work_unit_retired_with_connection(&connection, work_id, unit_id, retired) 4411: } 4412: 4413: #[tauri::command] 4414: fn set_all_work_units_retired( 4415: work_id: i64, 4416: retired: bool, 4417: database: State<'_, Database>, 4418: ) -> Result { 4419: let connection = database 4420: .connection 4421: .lock() 4422: .map_err(|error| error.to_string())?; 4423: 4424: set_all_work_units_retired_with_connection(&connection, work_id, retired) 4425: } 4426: 4427: fn create_work_unit_with_connection( 4428: connection: &Connection, 4429: work_id: i64, 4430: parent_unit_id: Option, 4431: unit_type: String, 4432: label: String, ===== #[tauri::command] — lignes 5046 à 5088 ===== 5046: let types = rows 5047: .collect::, _>>() 5048: .map_err(|error| error.to_string())?; 5049: 5050: validate_relation_types(&types)?; 5051: Ok(types) 5052: } 5053: 5054: #[tauri::command] 5055: fn list_relation_types(database: State<'_, Database>) -> Result, String> { 5056: let connection = database 5057: .connection 5058: .lock() 5059: .map_err(|error| error.to_string())?; 5060: 5061: load_relation_types(&connection) 5062: } 5063: 5064: #[tauri::command] 5065: fn list_genres(database: State<'_, Database>) -> Result, String> { 5066: let connection = database 5067: .connection 5068: .lock() 5069: .map_err(|error| error.to_string())?; 5070: 5071: Ok( 5072: list_catalog_tags_with_connection(&connection, "genres", false)? 5073: .into_iter() 5074: .map(|entry| entry.name) 5075: .collect(), 5076: ) 5077: } 5078: 5079: #[tauri::command] 5080: fn list_all_genres(database: State<'_, Database>) -> Result, String> { 5081: let connection = database 5082: .connection 5083: .lock() 5084: .map_err(|error| error.to_string())?; 5085: 5086: list_catalog_tags_with_connection(&connection, "genres", true) 5087: } 5088: ===== #[tauri::command] — lignes 5091 à 5133 ===== 5091: let connection = database 5092: .connection 5093: .lock() 5094: .map_err(|error| error.to_string())?; 5095: 5096: add_or_reactivate_catalog_tag_with_connection(&connection, "genres", &name) 5097: } 5098: 5099: #[tauri::command] 5100: fn retire_genre(name: String, database: State<'_, Database>) -> Result<(), String> { 5101: let connection = database 5102: .connection 5103: .lock() 5104: .map_err(|error| error.to_string())?; 5105: 5106: retire_catalog_tag_with_connection(&connection, "genres", &name) 5107: } 5108: 5109: #[tauri::command] 5110: fn list_demographics(database: State<'_, Database>) -> Result, String> { 5111: let connection = database 5112: .connection 5113: .lock() 5114: .map_err(|error| error.to_string())?; 5115: 5116: Ok( 5117: list_catalog_tags_with_connection(&connection, "demographics", false)? 5118: .into_iter() 5119: .map(|entry| entry.name) 5120: .collect(), 5121: ) 5122: } 5123: 5124: #[tauri::command] 5125: fn list_all_demographics(database: State<'_, Database>) -> Result, String> { 5126: let connection = database 5127: .connection 5128: .lock() 5129: .map_err(|error| error.to_string())?; 5130: 5131: list_catalog_tags_with_connection(&connection, "demographics", true) 5132: } 5133: ===== #[tauri::command] — lignes 5139 à 5181 ===== 5139: let connection = database 5140: .connection 5141: .lock() 5142: .map_err(|error| error.to_string())?; 5143: 5144: add_or_reactivate_catalog_tag_with_connection(&connection, "demographics", &name) 5145: } 5146: 5147: #[tauri::command] 5148: fn retire_demographic(name: String, database: State<'_, Database>) -> Result<(), String> { 5149: let connection = database 5150: .connection 5151: .lock() 5152: .map_err(|error| error.to_string())?; 5153: 5154: retire_catalog_tag_with_connection(&connection, "demographics", &name) 5155: } 5156: 5157: fn load_catalog_entries( 5158: connection: &Connection, 5159: table: &str, 5160: key_column: &str, 5161: ) -> Result, String> { 5162: // Les noms de tables et colonnes sont exclusivement définis 5163: // par les appels internes ci-dessous. 5164: let sql = format!( 5165: "SELECT {key_column}, label, is_available 5166: FROM {table} 5167: ORDER BY label COLLATE NOCASE" 5168: ); 5169: 5170: let mut statement = connection 5171: .prepare(&sql) 5172: .map_err(|error| error.to_string())?; 5173: 5174: let rows = statement 5175: .query_map([], |row| { 5176: Ok(CatalogEntry { 5177: key: row.get(0)?, 5178: label: row.get(1)?, 5179: active: row.get::<_, i64>(2)? != 0, 5180: }) 5181: }) ===== #[tauri::command] — lignes 5190 à 5232 ===== 5190: let connection = database 5191: .connection 5192: .lock() 5193: .map_err(|error| error.to_string())?; 5194: 5195: load_catalog_entries(&connection, "editorial_forms", "form_key") 5196: } 5197: 5198: #[tauri::command] 5199: fn list_erotic_tag_forms(database: State<'_, Database>) -> Result, String> { 5200: let connection = database 5201: .connection 5202: .lock() 5203: .map_err(|error| error.to_string())?; 5204: 5205: let mut statement = connection 5206: .prepare( 5207: "SELECT fet.form_key 5208: FROM form_erotic_tags fet 5209: JOIN editorial_forms ef ON ef.form_key = fet.form_key 5210: WHERE ef.is_available = 1 5211: ORDER BY ef.label COLLATE NOCASE", 5212: ) 5213: .map_err(|error| error.to_string())?; 5214: 5215: let rows = statement 5216: .query_map([], |row| row.get::<_, String>(0)) 5217: .map_err(|error| error.to_string())?; 5218: 5219: rows.collect::, _>>() 5220: .map_err(|error| error.to_string()) 5221: } 5222: 5223: #[tauri::command] 5224: fn list_editorial_subforms( 5225: database: State<'_, Database>, 5226: ) -> Result, String> { 5227: let connection = database 5228: .connection 5229: .lock() 5230: .map_err(|error| error.to_string())?; 5231: 5232: let mut statement = connection ===== #[tauri::command] — lignes 5251 à 5293 ===== 5251: }) 5252: }) 5253: .map_err(|error| error.to_string())?; 5254: 5255: rows.collect::, _>>() 5256: .map_err(|error| error.to_string()) 5257: } 5258: 5259: #[tauri::command] 5260: fn list_original_languages(database: State<'_, Database>) -> Result, String> { 5261: let connection = database 5262: .connection 5263: .lock() 5264: .map_err(|error| error.to_string())?; 5265: 5266: load_catalog_entries(&connection, "original_languages", "language_key") 5267: } 5268: 5269: #[tauri::command] 5270: fn list_publisher_types(database: State<'_, Database>) -> Result, String> { 5271: let connection = database 5272: .connection 5273: .lock() 5274: .map_err(|error| error.to_string())?; 5275: 5276: load_catalog_entries(&connection, "publisher_types", "publisher_type_key") 5277: } 5278: 5279: #[tauri::command] 5280: fn list_work_statuses(database: State<'_, Database>) -> Result, String> { 5281: let connection = database 5282: .connection 5283: .lock() 5284: .map_err(|error| error.to_string())?; 5285: 5286: load_catalog_entries(&connection, "work_statuses", "status_key") 5287: } 5288: 5289: fn validate_link_type_key(key: &str) -> Result<(), String> { 5290: let bytes = key.as_bytes(); 5291: 5292: let valid = !bytes.is_empty() 5293: && bytes[0].is_ascii_lowercase() ===== #[tauri::command] — lignes 5667 à 5709 ===== 5667: 5668: if changed == 0 { 5669: return Err("Langue de traduction introuvable.".to_string()); 5670: } 5671: 5672: Ok(()) 5673: } 5674: 5675: #[tauri::command] 5676: fn list_translation_languages( 5677: database: State<'_, Database>, 5678: ) -> Result, String> { 5679: let connection = database 5680: .connection 5681: .lock() 5682: .map_err(|error| error.to_string())?; 5683: 5684: list_translation_languages_with_connection(&connection) 5685: } 5686: 5687: #[tauri::command] 5688: fn add_or_reactivate_translation_language( 5689: key: String, 5690: label: String, 5691: database: State<'_, Database>, 5692: ) -> Result<(), String> { 5693: let connection = database 5694: .connection 5695: .lock() 5696: .map_err(|error| error.to_string())?; 5697: 5698: add_or_reactivate_translation_language_with_connection(&connection, &key, &label) 5699: } 5700: 5701: #[tauri::command] 5702: fn retire_translation_language(key: String, database: State<'_, Database>) -> Result<(), String> { 5703: let connection = database 5704: .connection 5705: .lock() 5706: .map_err(|error| error.to_string())?; 5707: 5708: retire_translation_language_with_connection(&connection, &key) 5709: } ===== #[tauri::command] — lignes 5805 à 5847 ===== 5805: "Cette entrée de traduction est déjà renseignée à l'identique.".to_string(), 5806: ); 5807: } 5808: } 5809: 5810: Ok(()) 5811: } 5812: 5813: #[tauri::command] 5814: fn list_translation_types(database: State<'_, Database>) -> Result, String> { 5815: let connection = database 5816: .connection 5817: .lock() 5818: .map_err(|error| error.to_string())?; 5819: 5820: list_translation_types_with_connection(&connection) 5821: } 5822: 5823: #[tauri::command] 5824: fn add_or_reactivate_translation_type( 5825: key: String, 5826: label: String, 5827: database: State<'_, Database>, 5828: ) -> Result<(), String> { 5829: let connection = database 5830: .connection 5831: .lock() 5832: .map_err(|error| error.to_string())?; 5833: 5834: add_or_reactivate_translation_type_with_connection(&connection, &key, &label) 5835: } 5836: 5837: #[tauri::command] 5838: fn retire_translation_type(key: String, database: State<'_, Database>) -> Result<(), String> { 5839: let connection = database 5840: .connection 5841: .lock() 5842: .map_err(|error| error.to_string())?; 5843: 5844: retire_translation_type_with_connection(&connection, &key) 5845: } 5846: 5847: #[tauri::command] ===== #[tauri::command] — lignes 5849 à 5891 ===== 5849: let connection = database 5850: .connection 5851: .lock() 5852: .map_err(|error| error.to_string())?; 5853: 5854: list_link_types_with_connection(&connection) 5855: } 5856: 5857: #[tauri::command] 5858: fn add_or_reactivate_link_type( 5859: key: String, 5860: label: String, 5861: database: State<'_, Database>, 5862: ) -> Result<(), String> { 5863: let connection = database 5864: .connection 5865: .lock() 5866: .map_err(|error| error.to_string())?; 5867: 5868: add_or_reactivate_link_type_with_connection(&connection, &key, &label) 5869: } 5870: 5871: #[tauri::command] 5872: fn retire_link_type(key: String, database: State<'_, Database>) -> Result<(), String> { 5873: let connection = database 5874: .connection 5875: .lock() 5876: .map_err(|error| error.to_string())?; 5877: 5878: retire_link_type_with_connection(&connection, &key) 5879: } 5880: 5881: #[tauri::command] 5882: fn list_unit_types(database: State<'_, Database>) -> Result, String> { 5883: let connection = database 5884: .connection 5885: .lock() 5886: .map_err(|error| error.to_string())?; 5887: 5888: let mut statement = connection 5889: .prepare( 5890: "SELECT unit_type, label, is_available, is_main 5891: FROM unit_types ===== #[tauri::command] — lignes 5941 à 5983 ===== 5941: #[serde(rename_all = "camelCase")] 5942: struct UnitRules { 5943: form_types: Vec, 5944: subform_types: Vec, 5945: root_types: Vec, 5946: parent_rules: Vec, 5947: } 5948: 5949: #[tauri::command] 5950: fn list_unit_rules(database: State<'_, Database>) -> Result { 5951: let connection = database 5952: .connection 5953: .lock() 5954: .map_err(|error| error.to_string())?; 5955: 5956: let form_types = { 5957: let mut statement = connection 5958: .prepare( 5959: "SELECT form_key, unit_type 5960: FROM form_unit_types 5961: ORDER BY form_key, unit_type", 5962: ) 5963: .map_err(|error| error.to_string())?; 5964: 5965: let rows = statement 5966: .query_map([], |row| { 5967: Ok(FormUnitTypeRule { 5968: form_key: row.get(0)?, 5969: unit_type: row.get(1)?, 5970: }) 5971: }) 5972: .map_err(|error| error.to_string())?; 5973: 5974: rows.collect::, _>>() 5975: .map_err(|error| error.to_string())? 5976: }; 5977: 5978: let subform_types = { 5979: let mut statement = connection 5980: .prepare( 5981: "SELECT form_key, subform_key, unit_type 5982: FROM subform_unit_types 5983: ORDER BY form_key, subform_key, unit_type", ===== #[tauri::command] — lignes 6085 à 6127 ===== 6085: }) 6086: }) 6087: .map_err(|error| error.to_string())?; 6088: 6089: rows.collect::, _>>() 6090: .map_err(|error| error.to_string()) 6091: } 6092: 6093: #[tauri::command] 6094: fn list_work_size_rules(database: State<'_, Database>) -> Result, String> { 6095: let connection = database 6096: .connection 6097: .lock() 6098: .map_err(|error| error.to_string())?; 6099: 6100: list_work_size_rules_with_connection(&connection) 6101: } 6102: 6103: #[derive(Debug, Clone, Serialize)] 6104: #[serde(rename_all = "camelCase")] 6105: struct FormOneShotRule { 6106: form_key: String, 6107: allowed: bool, 6108: } 6109: 6110: #[tauri::command] 6111: fn list_form_one_shot_rules(database: State<'_, Database>) -> Result, String> { 6112: let connection = database 6113: .connection 6114: .lock() 6115: .map_err(|error| error.to_string())?; 6116: 6117: let mut statement = connection 6118: .prepare( 6119: "SELECT form_key, allowed 6120: FROM form_one_shot_rules 6121: ORDER BY form_key", 6122: ) 6123: .map_err(|error| error.to_string())?; 6124: 6125: let rows = statement 6126: .query_map([], |row| { 6127: Ok(FormOneShotRule { ===== #[tauri::command] — lignes 7177 à 7219 ===== 7177: } 7178: } 7179: 7180: let _ = resource_paths; 7181: result.finish(); 7182: result 7183: } 7184: 7185: #[tauri::command] 7186: fn analyze_portable_library(portable_directory: String) -> PortableLibraryAnalysisResult { 7187: let root = PathBuf::from(portable_directory); 7188: analyze_portable_library_internal(&root) 7189: } 7190: 7191: fn portable_safe_path(root: &Path, relative_path: &str) -> Result { 7192: let relative = Path::new(relative_path); 7193: 7194: if relative_path.trim().is_empty() 7195: || relative 7196: .components() 7197: .all(|component| matches!(component, std::path::Component::CurDir)) 7198: || relative.is_absolute() 7199: || relative.components().any(|component| { 7200: matches!( 7201: component, 7202: std::path::Component::ParentDir 7203: | std::path::Component::RootDir 7204: | std::path::Component::Prefix(_) 7205: ) 7206: }) 7207: { 7208: return Err("Chemin relatif invalide ou dangereux.".to_string()); 7209: } 7210: 7211: let candidate = root.join(relative); 7212: let mut current = root.to_path_buf(); 7213: 7214: for component in relative.components() { 7215: if let std::path::Component::Normal(part) = component { 7216: current.push(part); 7217: 7218: match std::fs::symlink_metadata(¤t) { 7219: Ok(metadata) => { ===== #[tauri::command] — lignes 7296 à 7338 ===== 7296: 7297: if bytes.len() != 16 || bytes[6] >> 4 != 4 || bytes[8] >> 6 != 2 { 7298: return Err("L'identifiant fourni doit être un UUID version 4.".into()); 7299: } 7300: 7301: Ok(()) 7302: } 7303: 7304: #[tauri::command] 7305: fn create_portable_library( 7306: parent_directory: String, 7307: name: String, 7308: library_uuid: String, 7309: created_at: String, 7310: ) -> Result { 7311: let clean_name = name.trim(); 7312: 7313: if clean_name.is_empty() || clean_name.len() > 120 { 7314: return Err("Le nom doit contenir entre 1 et 120 caractères.".into()); 7315: } 7316: 7317: if clean_name == "." 7318: || clean_name == ".." 7319: || clean_name 7320: .chars() 7321: .any(|character| character == '/' || character == '\\' || character.is_control()) 7322: { 7323: return Err("Le nom contient des caractères interdits.".into()); 7324: } 7325: 7326: validate_portable_uuid_v4(&library_uuid)?; 7327: 7328: if created_at.len() < 20 || !created_at.contains('T') || !created_at.ends_with('Z') { 7329: return Err("Date de création ISO 8601 invalide.".into()); 7330: } 7331: 7332: let parent = PathBuf::from(parent_directory) 7333: .canonicalize() 7334: .map_err(|error| format!("Dossier parent inaccessible : {error}"))?; 7335: 7336: if !parent.is_dir() { 7337: return Err("Le dossier parent sélectionné n'est pas un dossier.".into()); 7338: } guidelumineux@fairytail01:~/Bibliotheca-Test/bibliotheca-app$