summaryrefslogtreecommitdiff
path: root/src/commands/modification.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 12:31:02 +0200
committerfxqnlr <[email protected]>2024-09-04 12:31:02 +0200
commit942558c75200aaad0b4d8561a1f6999f88f843a4 (patch)
tree8be4632c0677613c277403cb11d41cb6dff12b5b /src/commands/modification.rs
parent29635b9e3833296b2c908914104ba7165d22d3d5 (diff)
downloadmodlist-942558c75200aaad0b4d8561a1f6999f88f843a4.tar
modlist-942558c75200aaad0b4d8561a1f6999f88f843a4.tar.gz
modlist-942558c75200aaad0b4d8561a1f6999f88f843a4.zip
remove allow too_many_lines and fix them
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r--src/commands/modification.rs114
1 files changed, 56 insertions, 58 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index aa1174a..8f115ee 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -1,5 +1,3 @@
1#![allow(clippy::too_many_lines)]
2
3use std::collections::HashMap; 1use std::collections::HashMap;
4 2
5use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 3use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
@@ -114,60 +112,7 @@ pub async fn mod_add(
114 ); 112 );
115 113
116 for project in projectinfo { 114 for project in projectinfo {
117 project_p.set_message(format!("Add {}", project.title)); 115 add_project(config, &project_p, &project, &list)?;
118
119 let current_version_id = if project.current_version.is_none() {
120 String::from("NONE")
121 } else {
122 project
123 .current_version
124 .clone()
125 .ok_or(MLErr::new(EType::Other, "cur_ver"))?
126 .id
127 };
128
129 match userlist_insert(
130 config,
131 &list.id,
132 &project.mod_id,
133 &current_version_id,
134 &project.applicable_versions,
135 &project.download_link,
136 project.set_version,
137 ) {
138 Err(e) => {
139 let expected_err = format!(
140 "SQL: UNIQUE constraint failed: {}.mod_id",
141 list.id
142 );
143 if e.to_string() == expected_err {
144 Err(MLErr::new(
145 EType::ModError,
146 "MOD_ALREADY_ON_SELECTED_LIST",
147 ))
148 } else {
149 Err(e)
150 }
151 }
152 Ok(..) => Ok(..),
153 }?;
154
155 match mods_insert(
156 config,
157 &project.mod_id,
158 &project.slug,
159 &project.title,
160 ) {
161 Err(e) => {
162 if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" {
163 Ok(..)
164 } else {
165 Err(e)
166 }
167 }
168 Ok(..) => Ok(..),
169 }?;
170
171 if project.current_version.is_some() { 116 if project.current_version.is_some() {
172 downloadstack.push( 117 downloadstack.push(
173 project 118 project
@@ -175,8 +120,6 @@ pub async fn mod_add(
175 .ok_or(MLErr::new(EType::Other, "cur_ver"))?, 120 .ok_or(MLErr::new(EType::Other, "cur_ver"))?,
176 ); 121 );
177 }; 122 };
178
179 project_p.inc(1);
180 } 123 }
181 124
182 project_p.finish_with_message("Added all mods to the database"); 125 project_p.finish_with_message("Added all mods to the database");
@@ -199,6 +142,61 @@ pub async fn mod_add(
199 Ok(()) 142 Ok(())
200} 143}
201 144
145fn add_project(
146 config: &Cfg,
147 project_p: &ProgressBar,
148 project: &ProjectInfo,
149 list: &List,
150) -> MLE<()> {
151 project_p.set_message(format!("Add {}", project.title));
152
153 let current_version_id = if project.current_version.is_none() {
154 String::from("NONE")
155 } else {
156 project
157 .current_version
158 .clone()
159 .ok_or(MLErr::new(EType::Other, "cur_ver"))?
160 .id
161 };
162
163 match userlist_insert(
164 config,
165 &list.id,
166 &project.mod_id,
167 &current_version_id,
168 &project.applicable_versions,
169 &project.download_link,
170 project.set_version,
171 ) {
172 Err(e) => {
173 let expected_err =
174 format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id);
175 if e.to_string() == expected_err {
176 Err(MLErr::new(EType::ModError, "MOD_ALREADY_ON_SELECTED_LIST"))
177 } else {
178 Err(e)
179 }
180 }
181 Ok(..) => Ok(..),
182 }?;
183
184 match mods_insert(config, &project.mod_id, &project.slug, &project.title) {
185 Err(e) => {
186 if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" {
187 Ok(..)
188 } else {
189 Err(e)
190 }
191 }
192 Ok(..) => Ok(..),
193 }?;
194
195 project_p.inc(1);
196
197 Ok(())
198}
199
202async fn get_mod_infos( 200async fn get_mod_infos(
203 config: &Cfg, 201 config: &Cfg,
204 mod_ids: Vec<(String, bool)>, 202 mod_ids: Vec<(String, bool)>,