|
| 1 | +async function setMangaListFilterOptions() { |
| 2 | + const url = 'https://api.mangacopy.com/api/v3/h5/filter/comic/tags'; |
| 3 | + try { |
| 4 | + let result = [{ |
| 5 | + label: '主题', |
| 6 | + name: 'theme', |
| 7 | + options: [{ |
| 8 | + label: '推荐', |
| 9 | + value: 'recommend' |
| 10 | + }, { |
| 11 | + label: '全部', |
| 12 | + value: 0 |
| 13 | + }] |
| 14 | + }, |
| 15 | + { |
| 16 | + label: '地区/进度', |
| 17 | + name: 'top', |
| 18 | + options: [{ |
| 19 | + label: '全部', |
| 20 | + value: 0 |
| 21 | + }] |
| 22 | + } |
| 23 | + ] |
| 24 | + const rawResponse = await window.Rulia.httpRequest({ |
| 25 | + url: url, |
| 26 | + method: 'GET', |
| 27 | + payload: 'format=json&type=1' |
| 28 | + }); |
| 29 | + const response = JSON.parse(rawResponse); |
| 30 | + for (var item of response.results.theme) { |
| 31 | + result[0].options.push({ |
| 32 | + label: item.name, |
| 33 | + value: item.path_word |
| 34 | + }) |
| 35 | + } |
| 36 | + for (var item of response.results.top) { |
| 37 | + result[1].options.push({ |
| 38 | + label: item.name, |
| 39 | + value: item.path_word |
| 40 | + }) |
| 41 | + } |
| 42 | + window.Rulia.endWithResult(result); |
| 43 | + } catch (error) { |
| 44 | + window.Rulia.endWithResult([]) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | + |
1 | 49 | async function getMangaListByRecommend(page, pageSize) { |
2 | 50 | const url = |
3 | 51 | 'https://api.mangacopy.com/api/v3/recs'; |
@@ -25,6 +73,46 @@ async function getMangaListByRecommend(page, pageSize) { |
25 | 73 | } |
26 | 74 | } |
27 | 75 |
|
| 76 | +async function getMangaListByCategory(page, pageSize, filterOptions) { |
| 77 | + if (filterOptions.theme == 'recommend') { |
| 78 | + return await getMangaListByRecommend(page, pageSize); |
| 79 | + } else { |
| 80 | + const url = 'https://api.mangacopy.com/api/v3/comics'; |
| 81 | + try { |
| 82 | + var theme = ''; |
| 83 | + var top = ''; |
| 84 | + if (filterOptions.theme && filterOptions.theme != 0) { |
| 85 | + theme = '&theme=' + filterOptions.theme; |
| 86 | + } |
| 87 | + if (filterOptions.top && filterOptions.top != 0) { |
| 88 | + top = '&top=' + filterOptions.top; |
| 89 | + } |
| 90 | + var payload = '_update=true&format=json&free_type=1&limit=' + pageSize + '&offset=' + ((page - 1) * |
| 91 | + pageSize) + '&ordering=popular' + theme + top; |
| 92 | + const rawResponse = await window.Rulia.httpRequest({ |
| 93 | + url: url, |
| 94 | + method: 'GET', |
| 95 | + payload: payload |
| 96 | + }) |
| 97 | + const response = JSON.parse(rawResponse); |
| 98 | + var result = { |
| 99 | + list: [] |
| 100 | + } |
| 101 | + for (var manga of response.results.list) { |
| 102 | + var comic = { |
| 103 | + title: manga.name, |
| 104 | + url: 'https://www.mangacopy.com/comic/' + manga.path_word, |
| 105 | + coverUrl: manga.cover |
| 106 | + } |
| 107 | + result.list.push(comic); |
| 108 | + } |
| 109 | + window.Rulia.endWithResult(result); |
| 110 | + } catch (error) { |
| 111 | + window.Rulia.endWithException(error.message); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
28 | 116 | async function getMangaListBySearching(page, pageSize, keyword) { |
29 | 117 | const url = |
30 | 118 | 'https://api.mangacopy.com/api/v3/search/comic'; |
@@ -53,11 +141,11 @@ async function getMangaListBySearching(page, pageSize, keyword) { |
53 | 141 | } |
54 | 142 | } |
55 | 143 |
|
56 | | -async function getMangaList(page, pageSize, keyword) { |
| 144 | +async function getMangaList(page, pageSize, keyword, rawFilterOptions) { |
57 | 145 | if (keyword) { |
58 | 146 | return await getMangaListBySearching(page, pageSize, keyword); |
59 | 147 | } else { |
60 | | - return await getMangaListByRecommend(page, pageSize); |
| 148 | + return await getMangaListByCategory(page, pageSize, JSON.parse(rawFilterOptions)); |
61 | 149 | } |
62 | 150 | } |
63 | 151 |
|
|
0 commit comments