Skip to content

Commit d62e671

Browse files
committed
format: 移除不必要的内容
1 parent e2fc116 commit d62e671

File tree

10 files changed

+20
-210
lines changed

10 files changed

+20
-210
lines changed

mcim_sync/apis/modrinth.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,9 @@ def get_project_all_version(
1313
) -> List[dict]:
1414
res = request(f"{API}/v2/project/{project_id}/version").json()
1515
return res
16-
# latest_version_id_list = []
17-
18-
# with ModelSubmitter() as submitter:
19-
# for version in res:
20-
# latest_version_id_list.append(version["id"])
21-
# for file in version["files"]:
22-
# file["version_id"] = version["id"]
23-
# file["project_id"] = version["project_id"]
24-
# file_model = File(**file)
25-
# if config.file_cdn:
26-
# if (
27-
# need_to_cache
28-
# and file_model.size <= MAX_LENGTH
29-
# and file_model.filename
30-
# and file_model.url
31-
# and file_model.hashes.sha1
32-
# ):
33-
# submitter.add(
34-
# FileCDN(
35-
# url=file_model.url,
36-
# sha1=file_model.hashes.sha1,
37-
# size=file_model.size,
38-
# mtime=int(time.time()),
39-
# path=file_model.hashes.sha1,
40-
# ) # type: ignore
41-
# )
42-
# file_model.file_cdn_cached = True
43-
# submitter.add(file_model)
44-
# submitter.add(Version(**version))
45-
46-
# removed_count = mongodb_engine.remove(
47-
# Version,
48-
# query.not_in(Version.id, latest_version_id_list),
49-
# Version.project_id == project_id,
50-
# )
51-
# total_count = len(res)
52-
# log.info(
53-
# f"Finished sync project {project_id} versions info, total {total_count} versions, removed {removed_count} versions"
54-
# )
55-
# return total_count
56-
5716

5817
def get_project(project_id: str) -> dict:
5918
res = request(f"{API}/v2/project/{project_id}").json()
60-
# with ModelSubmitter() as submitter:
61-
# project_model = Project(**res)
62-
# submitter.add(project_model)
63-
# total_count = get_project_all_version(
64-
# project_id,
65-
# need_to_cache=project_model.project_type == "mod",
66-
# )
67-
# return ProjectDetail(id=project_id, name=res["slug"], version_count=total_count)
68-
6919
return res
7020

7121
def get_mutil_projects_info(project_ids: List[str]) -> List[dict]:
@@ -88,34 +38,16 @@ def get_multi_hashes_info(hashes: List[str], algorithm: str) -> dict:
8838

8939

9040
def get_categories() -> List[dict]:
91-
# mongodb_engine.remove(Category)
92-
# with ModelSubmitter() as submitter:
93-
# categories = request(f"{API}/v2/tag/category").json()
94-
# for category in categories:
95-
# submitter.add(Category(**category))
96-
# return categories
9741
res = request(f"{API}/v2/tag/category").json()
9842
return res
9943

10044

10145
def get_loaders() -> List[dict]:
102-
# mongodb_engine.remove(Loader)
103-
# with ModelSubmitter() as submitter:
104-
# loaders = request(f"{API}/v2/tag/loader").json()
105-
# for loader in loaders:
106-
# submitter.add(Loader(**loader))
107-
# return loaders
10846
res = request(f"{API}/v2/tag/loader").json()
10947
return res
11048

11149

11250
def get_game_versions() -> List[dict]:
113-
# mongodb_engine.remove(GameVersion)
114-
# with ModelSubmitter() as submitter:
115-
# game_versions = request(f"{API}/v2/tag/game_version").json()
116-
# for game_version in game_versions:
117-
# submitter.add(GameVersion(**game_version))
118-
# return game_versions
11951
res = request(f"{API}/v2/tag/game_version").json()
12052
return res
12153

mcim_sync/config.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,33 @@ class DomainRateLimitModel(BaseModel):
6262

6363
class ConfigModel(BaseModel):
6464
debug: bool = False
65+
66+
# 数据库配置
6567
mongodb: MongodbConfigModel = MongodbConfigModel()
6668
redis: RedisConfigModel = RedisConfigModel()
69+
6770
job_config: JobConfigModel = JobConfigModel()
6871
interval: JobInterval = JobInterval()
72+
6973
max_workers: int = 8
7074
curseforge_chunk_size: int = 1000
7175
modrinth_chunk_size: int = 100
7276
curseforge_delay: Union[float, int] = 1
7377
modrinth_delay: Union[float, int] = 1
78+
79+
# API 配置
7480
curseforge_api_key: str = "<api key>"
7581
curseforge_api: str = "https://api.curseforge.com" # 不然和api的拼接对不上
7682
modrinth_api: str = "https://api.modrinth.com"
83+
84+
# Telegram Bot 配置
7785
telegram_bot: bool = False
7886
bot_api: str = "https://api.telegram.org/bot"
7987
bot_token: str = "<bot token>"
8088
chat_id: str = "<chat id>"
81-
telegram_proxy: Optional[str] = None
89+
8290
proxies: Optional[str] = None
83-
file_cdn: bool = False
84-
max_file_size: int = 1024 * 1024 * 20 # 20MB
85-
log_to_file: bool = False
86-
log_path: str = "./logs"
91+
8792
# 域名限速配置
8893
domain_rate_limits: Dict[str, DomainRateLimitModel] = {
8994
"api.curseforge.com": DomainRateLimitModel(max_requests=100, time_window=60),

mcim_sync/database/mongodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odmantic import AIOEngine, SyncEngine
1+
from odmantic import SyncEngine
22
from pymongo import MongoClient
33
from pymongo.database import Database
44

mcim_sync/models/database/curseforge.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class File(Model):
9999
fileFingerprint: Optional[int] = None
100100
modules: Optional[List[Module]] = None
101101

102-
# file_cdn_cached: bool = False
103-
104102
sync_at: datetime = Field(default_factory=datetime.utcnow)
105103

106104
model_config = {

mcim_sync/models/database/file_cdn.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

mcim_sync/models/database/modrinth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class File(Model):
9090
version_id: str
9191
project_id: str
9292

93-
# file_cdn_cached: Optional[bool] = False
94-
9593
sync_at: datetime = Field(default_factory=datetime.utcnow)
9694

9795
model_config = {"collection": "modrinth_files"}

mcim_sync/sync/curseforge.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
get_search_result,
2121
)
2222

23-
# from mcim_sync.models.database.file_cdn import File as FileCDN
2423
from mcim_sync.utils.constans import ProjectDetail
2524
from mcim_sync.utils.loger import log
2625
from mcim_sync.utils.model_submitter import ModelSubmitter
@@ -33,16 +32,14 @@
3332
config = Config.load()
3433

3534
API = config.curseforge_api
36-
MAX_LENGTH = config.max_file_size
37-
MIN_DOWNLOAD_COUNT = 0
3835
HEADERS = {
3936
"x-api-key": config.curseforge_api_key,
4037
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.54",
4138
}
4239

4340

4441
def append_model_from_files_res(
45-
res, latestFiles: List[dict], need_to_cache: bool = True
42+
res, latestFiles: List[dict]
4643
):
4744
with ModelSubmitter() as submitter:
4845
for file in res["data"]:
@@ -54,36 +51,11 @@ def append_model_from_files_res(
5451
latestFiles=latestFiles, # type: ignore
5552
)
5653
)
57-
# file_sha1 = find_hash_in_curseforge_hashes(file["hashes"], 1)
58-
59-
# if config.file_cdn:
60-
# if (
61-
# file_model.fileLength is not None
62-
# and file_model.downloadCount is not None
63-
# and file_model.downloadUrl is not None
64-
# and file_sha1
65-
# ):
66-
# if (
67-
# need_to_cache
68-
# and file_model.gameId == 432
69-
# and file_model.fileLength <= MAX_LENGTH
70-
# and file_model.downloadCount >= MIN_DOWNLOAD_COUNT
71-
# ):
72-
# submitter.add(
73-
# FileCDN(
74-
# sha1=file_sha1,
75-
# url=file_model.downloadUrl,
76-
# path=file_sha1,
77-
# size=file_model.fileLength,
78-
# mtime=int(time.time()),
79-
# ) # type: ignore
80-
# )
81-
# file_model.file_cdn_cached = True
8254
submitter.add(file_model)
8355

8456

8557
def sync_mod_all_files(
86-
modId: int, latestFiles: List[dict], need_to_cache: bool = True
58+
modId: int, latestFiles: List[dict]
8759
) -> int:
8860
params = {"index": 0, "pageSize": 50}
8961
file_id_list = []
@@ -93,7 +65,7 @@ def sync_mod_all_files(
9365
while True:
9466
res = get_mod_files(modId, params["index"], params["pageSize"])
9567
append_model_from_files_res(
96-
res, latestFiles=latestFiles, need_to_cache=need_to_cache
68+
res, latestFiles=latestFiles
9769
)
9870
file_id_list.extend([file["id"] for file in res["data"]])
9971

@@ -118,7 +90,7 @@ def sync_mod_all_files(
11890

11991

12092
def sync_mod_all_files_at_once(
121-
modId: int, latestFiles: List[dict], need_to_cache: bool = True
93+
modId: int, latestFiles: List[dict]
12294
) -> Optional[int]:
12395
max_retries = 3
12496
page_size = 10000
@@ -147,7 +119,7 @@ def sync_mod_all_files_at_once(
147119
original_files_count = mongodb_engine.count(File, File.modId == modId)
148120

149121
append_model_from_files_res(
150-
res, latestFiles=latestFiles, need_to_cache=need_to_cache
122+
res, latestFiles=latestFiles
151123
)
152124

153125
removed_count = mongodb_engine.remove(
@@ -170,13 +142,11 @@ def sync_mod(modId: int) -> Optional[ProjectDetail]:
170142
# version_count = sync_mod_all_files(
171143
# modId,
172144
# latestFiles=res["latestFiles"],
173-
# need_to_cache=True if res["classId"] == 6 else False,
174145
# )
175146

176147
version_count = sync_mod_all_files_at_once(
177148
modId,
178149
latestFiles=res["latestFiles"],
179-
need_to_cache=True if res["classId"] == 6 else False,
180150
)
181151

182152
if version_count is None:

mcim_sync/sync/modrinth.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
"""
22
拉取 Modrinth 信息
3-
4-
version 信息包含了 file 信息,所以拉取 version 信息时,会拉取 version 下的所有 file 信息
5-
6-
sync_project 只刷新 project 信息,不刷新 project 下的 version 信息
7-
8-
刷新 project 信息后,会刷新 project 下的所有 version 信息,以及 version 下的所有 file 信息,不刷新 project 自身信息
93
"""
104

115
from tenacity import retry, stop_after_attempt, wait_fixed
12-
from typing import List, Optional, Union
6+
from typing import List, Optional
137
from odmantic import query
14-
import time
158

169
from mcim_sync.models.database.modrinth import (
1710
Project,
@@ -32,7 +25,6 @@
3225
get_multi_versions_info,
3326
get_search_result,
3427
)
35-
# from mcim_sync.models.database.file_cdn import File as FileCDN
3628
from mcim_sync.utils.constans import ProjectDetail
3729
from mcim_sync.exceptions import ResponseCodeException
3830
from mcim_sync.config import Config
@@ -44,10 +36,8 @@
4436
config = Config.load()
4537

4638
API = config.modrinth_api
47-
MAX_LENGTH = config.max_file_size
48-
4939

50-
def sync_project_all_version(project_id: str, need_to_cache: bool = True) -> int:
40+
def sync_project_all_version(project_id: str) -> int:
5141
res = get_project_all_version(project_id)
5242
latest_version_id_list = []
5343

@@ -61,24 +51,6 @@ def sync_project_all_version(project_id: str, need_to_cache: bool = True) -> int
6151
file["version_id"] = version["id"]
6252
file["project_id"] = version["project_id"]
6353
file_model = File(**file)
64-
# if config.file_cdn:
65-
# if (
66-
# need_to_cache
67-
# and file_model.size <= MAX_LENGTH
68-
# and file_model.filename
69-
# and file_model.url
70-
# and file_model.hashes.sha1
71-
# ):
72-
# submitter.add(
73-
# FileCDN(
74-
# url=file_model.url,
75-
# sha1=file_model.hashes.sha1,
76-
# size=file_model.size,
77-
# mtime=int(time.time()),
78-
# path=file_model.hashes.sha1,
79-
# ) # type: ignore
80-
# )
81-
# file_model.file_cdn_cached = True
8254
submitter.add(file_model)
8355
submitter.add(Version(**version))
8456

@@ -102,7 +74,6 @@ def sync_project(project_id: str) -> Optional[ProjectDetail]:
10274
project_model = Project(**res)
10375
total_count = sync_project_all_version(
10476
project_id,
105-
need_to_cache=project_model.project_type == "mod",
10677
)
10778
if total_count == 0:
10879
return None

0 commit comments

Comments
 (0)