Skip to content

Commit 101c82b

Browse files
authored
Merge pull request #1164 from tonymushah/1107-custom-list-forking
1107 custom list forking
2 parents bc0b66b + 8f7cc5f commit 101c82b

File tree

11 files changed

+648
-15
lines changed

11 files changed

+648
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "special-eureka",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"scripts": {
55
"vite:dev": "vite dev",
66
"codegen": "graphql-codegen",

src-tauri/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "special-eureka"
3-
version = "0.2.1"
3+
version = "0.2.2-1"
44
description = "a manga reader desktop app build with tauri"
55
authors = ["tonymushah"]
66
license = ""

src-tauri/mangadex/src/mutation/custom_list.rs

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
pub mod export;
22

3-
use crate::Result;
3+
use crate::{
4+
Result,
5+
store::types::structs::content::ContentFeeder,
6+
utils::{
7+
splittable_param::SendSplitted,
8+
traits_utils::{MangadexAsyncGraphQLContextExt, MangadexTauriManagerExt},
9+
},
10+
};
411
use async_graphql::{Context, Object};
5-
use mangadex_api_input_types::custom_list::{
6-
add_manga::CustomListAddMangaParam, create::CustomListCreateParam,
7-
remove_manga::CustomListRemoveMangaParam, update::CustomListUpdateParams,
12+
use mangadex_api_input_types::{
13+
custom_list::{
14+
add_manga::CustomListAddMangaParam, create::CustomListCreateParam,
15+
remove_manga::CustomListRemoveMangaParam, update::CustomListUpdateParams,
16+
},
17+
manga::list::MangaListParams,
818
};
9-
use mangadex_api_types_rust::RelationshipType;
19+
use mangadex_api_types_rust::{CustomListVisibility, RelationshipType};
1020
use uuid::Uuid;
1121

1222
use crate::{
@@ -147,4 +157,98 @@ impl CustomListMutations {
147157
pub async fn export(&self) -> export::CustomListExportMutations {
148158
export::CustomListExportMutations
149159
}
160+
pub async fn fork(
161+
&self,
162+
ctx: &Context<'_>,
163+
to_fork: Uuid,
164+
name: String,
165+
visibility: Option<CustomListVisibility>,
166+
filter_content: Option<bool>,
167+
) -> Result<CustomList> {
168+
let to_fork = {
169+
let client =
170+
get_mangadex_client_from_graphql_context_with_auth_refresh::<tauri::Wry>(ctx)
171+
.await?;
172+
client
173+
.custom_list()
174+
.id(to_fork)
175+
.get()
176+
.with_auth(true)
177+
.send()
178+
.await?
179+
};
180+
let manga_ids = {
181+
let ids = to_fork
182+
.data
183+
.find_relationships(RelationshipType::Manga)
184+
.into_iter()
185+
.map(|r| r.id)
186+
.collect::<Vec<_>>();
187+
if filter_content.unwrap_or_default() {
188+
let app = ctx.get_app_handle::<tauri::Wry>()?;
189+
let client = app.get_mangadex_client()?;
190+
app.feed(MangaListParams {
191+
manga_ids: ids,
192+
..Default::default()
193+
})
194+
.send_splitted_default(&client)
195+
.await?
196+
.data
197+
.into_iter()
198+
.map(|manga| manga.id)
199+
.collect()
200+
} else {
201+
ids
202+
}
203+
};
204+
let mut create = CustomListCreateParam {
205+
name,
206+
visibility,
207+
version: None,
208+
manga: {
209+
let mut m = manga_ids.clone();
210+
m.reverse();
211+
m
212+
},
213+
};
214+
215+
let mut skipped = 0;
216+
loop {
217+
if size_of_val(&create) >= 8000 {
218+
skipped += 10;
219+
create.manga = create.manga.into_iter().skip(skipped).collect();
220+
} else {
221+
break;
222+
}
223+
}
224+
let new_custom_list = {
225+
let client =
226+
get_mangadex_client_from_graphql_context_with_auth_refresh::<tauri::Wry>(ctx)
227+
.await?;
228+
create.send(&client).await?
229+
};
230+
231+
if skipped > 0 {
232+
self.add_manga_batch(
233+
ctx,
234+
new_custom_list.data.id,
235+
manga_ids.iter().skip(skipped).cloned().collect(),
236+
)
237+
.await?;
238+
}
239+
{
240+
let client =
241+
get_mangadex_client_from_graphql_context_with_auth_refresh::<tauri::Wry>(ctx)
242+
.await?;
243+
Ok(client
244+
.custom_list()
245+
.id(new_custom_list.data.id)
246+
.get()
247+
.with_auth(true)
248+
.send()
249+
.await?
250+
.data
251+
.into())
252+
}
253+
}
150254
}

0 commit comments

Comments
 (0)