@@ -68,7 +68,6 @@ def should_update_pack(modrinth_json):
68
68
69
69
def zip_and_post (modrinth_info , root ):
70
70
version = get_current_version (modrinth_info )
71
- project_id = get_project_id (modrinth_info )
72
71
relative_path = os .path .relpath (root , datapack_folder )
73
72
datapack_name = f"{ relative_path .replace (os .sep , '_' )} _v{ version } .zip"
74
73
full_datapack_path = os .path .join (root , datapack_name )
@@ -83,11 +82,38 @@ def zip_and_post(modrinth_info, root):
83
82
zipped_file .write (os .path .join (root , file ), arcname = file )
84
83
print (f"zipping { file } " )
85
84
85
+ post (modrinth_info , datapack_name , zipped_file_path )
86
+
87
+
88
+
89
+ def post (modrinth_info , datapack_name , zipped_file_path ):
90
+ version = get_current_version (modrinth_info )
91
+ project_id = get_project_id (modrinth_info )
92
+ ver_name = modrinth_info ["name" ]
93
+ changelog = modrinth_info ["changelog" ]
94
+ dependencies = modrinth_info ["dependencies" ]
95
+ supported_versions = modrinth_info ["supported_versions" ]
96
+ release_type = modrinth_info ["version_type" ]
97
+
86
98
files = {
87
- 'data' : (None , json .dumps (modrinth_info ), 'application/json' ),
88
- 'file' : (datapack_name , open (zipped_file_path , 'rb' ), 'application/zip' )
99
+ 'primary_file' : (datapack_name , open (zipped_file_path , 'rb' ), 'application/zip' )
100
+ }
101
+
102
+ payload = {
103
+ "name" : ver_name ,
104
+ "version_number" : version ,
105
+ "changelog" : changelog ,
106
+ "dependencies" : dependencies ,
107
+ "game_versions" : supported_versions ,
108
+ "version_type" : release_type ,
109
+ "loaders" : ['datapack' ],
110
+ "featured" : 'false' ,
111
+ "project_id" : project_id
89
112
}
90
- response = requests .post (modrinth_post_version_route , headers = {"Authorization" : modrinth_token }, files = files )
113
+
114
+
115
+
116
+ response = requests .post (modrinth_post_version_route , headers = {"Authorization" : modrinth_token }, files = files , data = payload )
91
117
upload_response = response .json ()
92
118
93
119
if 'error' not in upload_response :
@@ -96,26 +122,20 @@ def zip_and_post(modrinth_info, root):
96
122
print (f"Failed to upload { datapack_name } . Output:\n { upload_response } " )
97
123
98
124
99
-
100
125
def main ():
101
- print (f"Starting the datapack update process in { datapack_folder } ." )
102
126
for root , dirs , files in os .walk (datapack_folder ):
103
- print (f"Checking directory: { root } " )
104
127
if 'pack.mcmeta' not in files :
105
- print (f"{ root } is not a pack directory, skipping. " )
128
+ print (f"{ root } is not a pack directory, skipping" )
106
129
continue
107
130
if 'modrinth.json' not in files :
108
- print (f"{ root } does not have a modrinth.json file, skipping." )
131
+ print (f"{ root } does not have a modrinth json file, skipping" )
132
+ continue
133
+ datapack_info = get_datapack_info (os .path .join (root , "modrinth.json" ))
134
+ if not should_update_pack (datapack_info ):
109
135
continue
110
- try :
111
- datapack_info = get_datapack_info (os .path .join (root , "modrinth.json" ))
112
- if not should_update_pack (datapack_info ):
113
- print (f"Skipping { root } : no update needed." )
114
- continue
115
- print (f"Preparing to update { root } ." )
116
- zip_and_post (datapack_info , root )
117
- except Exception as e :
118
- print (f"Error processing directory { root } : { e } " )
136
+ zip_and_post (datapack_info , root )
137
+
138
+
119
139
120
140
if __name__ == "__main__" :
121
- main ()
141
+ main ()
0 commit comments