@@ -116,7 +116,7 @@ def sync_mod_all_files(
116
116
117
117
def sync_mod_all_files_at_once (
118
118
modId : int , latestFiles : List [dict ], need_to_cache : bool = True
119
- ) -> int :
119
+ ) -> Optional [ int ] :
120
120
res = get_mod_files (modId , index = 0 , pageSize = 10000 )
121
121
122
122
append_model_from_files_res (
@@ -127,11 +127,16 @@ def sync_mod_all_files_at_once(
127
127
128
128
page = Pagination (** res ["pagination" ])
129
129
130
+ if page .resultCount != page .totalCount :
131
+ log .warning (
132
+ f"ResultCount { page .resultCount } != TotalCount { page .totalCount } for mod { modId } , response maybe incomplete, passing sync"
133
+ )
134
+ return None
130
135
removed_count = mongodb_engine .remove (
131
136
File , File .modId == modId , query .not_in (File .id , file_id_list )
132
137
)
133
138
log .info (
134
- f"Finished sync mod { modId } , total { page .totalCount } files, removed { removed_count } files"
139
+ f"Finished sync mod { modId } , total { page .totalCount } files, resultCount { page . resultCount } , removed { removed_count } files"
135
140
)
136
141
137
142
return page .totalCount
@@ -144,8 +149,6 @@ def sync_mod(modId: int) -> Optional[ProjectDetail]:
144
149
res = get_mod (modId )
145
150
mod_model = Mod (** res )
146
151
if mod_model .gameId == 432 :
147
- submitter .add (mod_model )
148
-
149
152
# version_count = sync_mod_all_files(
150
153
# modId,
151
154
# latestFiles=res["latestFiles"],
@@ -158,13 +161,19 @@ def sync_mod(modId: int) -> Optional[ProjectDetail]:
158
161
need_to_cache = True if res ["classId" ] == 6 else False ,
159
162
)
160
163
164
+ if version_count is None :
165
+ return None
166
+
161
167
return ProjectDetail (
162
168
id = res ["id" ],
163
169
name = res ["name" ],
164
170
version_count = version_count ,
165
171
)
166
172
else :
167
173
log .debug (f"Mod { modId } gameId is not 432" )
174
+
175
+ # 最后再添加,以防未成功刷新版本列表而更新 Mod 信息
176
+ submitter .add (mod_model )
168
177
except ResponseCodeException as e :
169
178
if e .status_code == 404 :
170
179
log .error (f"Mod { modId } not found!" )
@@ -227,10 +236,12 @@ def sync_categories(
227
236
else :
228
237
raise e
229
238
239
+
230
240
class ModsSearchSortField (int , Enum ):
231
241
"""
232
242
https://docs.curseforge.com/rest-api/#tocS_ModsSearchSortField
233
243
"""
244
+
234
245
Featured = 1
235
246
Popularity = 2
236
247
LastUpdated = 3
@@ -249,6 +260,7 @@ class ModLoaderType(int, Enum):
249
260
"""
250
261
https://docs.curseforge.com/rest-api/#tocS_ModLoaderType
251
262
"""
263
+
252
264
Any = 0
253
265
Forge = 1
254
266
Cauldron = 2
@@ -257,13 +269,16 @@ class ModLoaderType(int, Enum):
257
269
Quilt = 5
258
270
NeoForge = 6
259
271
272
+
260
273
class ModsSearchSortOrder (str , Enum ):
261
274
"""
262
275
'asc' if sort is in ascending order, 'desc' if sort is in descending order
263
276
"""
277
+
264
278
ASC = "asc"
265
279
DESC = "desc"
266
280
281
+
267
282
@retry (stop = stop_after_attempt (3 ), wait = wait_fixed (1 ))
268
283
def fetch_search_result (
269
284
gameId : int = 432 ,
@@ -282,7 +297,8 @@ def fetch_search_result(
282
297
primaryAuthorId : Optional [int ] = None ,
283
298
slug : Optional [str ] = None ,
284
299
index : Optional [int ] = None ,
285
- pageSize : Optional [int ] = 50 ):
300
+ pageSize : Optional [int ] = 50 ,
301
+ ):
286
302
"""
287
303
Fetch search result from CurseForge API.
288
304
"""
@@ -304,12 +320,12 @@ def fetch_search_result(
304
320
primaryAuthorId = primaryAuthorId ,
305
321
slug = slug ,
306
322
index = index ,
307
- pageSize = pageSize
323
+ pageSize = pageSize ,
308
324
)
309
325
return res
310
326
except ResponseCodeException as e :
311
327
if e .status_code == 404 :
312
328
log .error ("Search result not found!" )
313
329
return None
314
330
else :
315
- raise e
331
+ raise e
0 commit comments