-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathuploader.py
More file actions
182 lines (149 loc) · 5.03 KB
/
uploader.py
File metadata and controls
182 lines (149 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import os
import requests
import json
# Per-mod: Update this for each mod!!!
MOD_ID = "tectonic"
MOD_VERSION = "3.0.22"
CHANGELOG = """
- Added `ore_fix` config option, which adjusts ore generation to be more consistent when below the usual minimum y value of -64.
- Fixed a crash with some mods that query chunk data on the client like JourneyMap.
- Fixed surface rules being broken with newer Clifftree versions.
- Lithostitched is now correctly marked as a dependency on Modrinth and Curseforge.
"""
UPLOAD_VERSIONS = [
("fabric", "21.1"),
("neoforge", "21.1"),
("fabric", "26.1"),
("neoforge", "26.1"),
]
DEPENDENCIES = [
{
"name": "Lithostitched",
"project_id": "XaDC71GB",
"dependency_type": "required",
"modId": 936015,
"relationType": 3,
}
]
MODRINTH_ID = "lWDHr9jE"
CURSEFORGE_ID = "686836"
RELEASE_TYPE = "release"
# Global: Should usually not be touched!
BASE_FOLDER = os.path.dirname(os.path.abspath(__file__))
MODRINTH_TOKEN = os.getenv('TOKEN_MR')
if not MODRINTH_TOKEN:
raise EnvironmentError("MODRINTH_TOKEN is unset!")
MODRINTH_GAME_VERSIONS = {
"21.1": ["1.21.1"],
"26.1": ["26.1"],
}
CURSEFORGE_TOKEN = os.getenv('TOKEN_CF')
if not CURSEFORGE_TOKEN:
raise EnvironmentError("CURSEFORGE_TOKEN is unset!")
CURSEFORGE_URL = f"https://minecraft.curseforge.com/api/v1/projects/{CURSEFORGE_ID}/upload-file"
CURSEFORGE_GAME_VERSIONS = {
"21.1": [11779],
"26.1": [15933],
}
CURSEFORGE_LOADERS = {
"fabric": 7499,
"forge": 7498,
"neoforge": 10150,
}
# Code
def upload_modrinth(loader: str, version: str, file_path: str, dependencies):
game_versions = MODRINTH_GAME_VERSIONS.get(version)
metadata = {
"name": f"v{MOD_VERSION} ~ {loader.title()} {version}",
"version_number": f"{MOD_VERSION}-{loader}-{version}",
"project_id": MODRINTH_ID,
"game_versions": game_versions,
"loaders": [loader],
"featured": True,
"changelog": CHANGELOG,
"version_type": RELEASE_TYPE,
"file_parts": ["file"],
"dependencies": dependencies
}
with open(file_path, 'rb') as mod_file:
response = requests.post(
"https://api.modrinth.com/v2/version",
headers={
"Authorization": MODRINTH_TOKEN
},
files={
'file': (os.path.basename(file_path), mod_file, 'application/java-archive'),
},
data={
'data': json.dumps(metadata)
}
)
name = f"MR {loader.title()} {version}: "
if response.status_code == 200:
print(name + "Success")
print(response.json())
else:
print(name + f"Failed ({response.status_code})")
print(response.text)
def upload_curseforge(loader: str, version: str, file_path: str, dependencies):
headers = {
"X-Api-Token": CURSEFORGE_TOKEN
}
# Lookup version and loader IDs
game_version_ids = CURSEFORGE_GAME_VERSIONS.get(version)
modloader_id = CURSEFORGE_LOADERS.get(loader)
if not game_version_ids or not modloader_id:
print(f"Skipping CurseForge upload for {loader} {version}: unknown IDs")
return
# Metadata
metadata = {
"displayName": f"v{MOD_VERSION} ~ {loader.title()} {version}",
"gameVersions": game_version_ids + [modloader_id],
"releaseType": RELEASE_TYPE,
"changelog": CHANGELOG,
"changelogType": "markdown",
"dependencies": dependencies
}
metastr = json.dumps(metadata)
with open(file_path, "rb") as mod_file:
files = {
"file": (os.path.basename(file_path), mod_file, "application/java-archive")
}
response = requests.post(
f"https://minecraft.curseforge.com/api/projects/{CURSEFORGE_ID}/upload-file",
headers=headers,
files=files,
data={"metadata": metastr},
auth=("Apollo", CURSEFORGE_TOKEN)
)
name = f"CF {loader.title()} {version}: "
if response.status_code == 200:
print(name + "Success")
print(response.json())
else:
print(name + f"Failed ({response.status_code})")
print(response.text)
for modloader, game_version in UPLOAD_VERSIONS:
mod_path = os.path.join(
BASE_FOLDER,
'build',
'libs',
f'{MOD_ID}-{MOD_VERSION}-{modloader}-{game_version}.jar'
)
dependencies = DEPENDENCIES.copy()
if (modloader == "fabric"):
dependencies.append(
{
"mod_name": "Fabric API",
"modId": 306612,
"relationType": 3,
"project_id": "P7dR8mSH",
"dependency_type": "required"
}
)
if not os.path.exists(mod_path):
print(f"File not found, skipping: {mod_path}")
continue
upload_modrinth(modloader, game_version, mod_path, dependencies)
upload_curseforge(modloader, game_version, mod_path, dependencies)
input("Press any key to close")