-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_version_curseforge.js
62 lines (55 loc) · 1.73 KB
/
create_version_curseforge.js
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
// This is probably the worst API I ever had to interact with.
const axios = require('axios').default;
const FormData = require('form-data');
const fs = require("node:fs");
function escapeControlCharacters(str) {
return str.replace(/[\0-\x1F\x7F]/g, (char) => {
switch (char) {
case '\n':
return '\\n';
case '\r':
return '\\r';
case '\t':
return '\\t';
case '\b':
return '\\b';
case '\f':
return '\\f';
case '\v':
return '\\v';
case '\0':
return '\\0';
default:
return '\\x' + char.charCodeAt(0).toString(16).padStart(2, '0');
}
});
}
module.exports = {
verifyConditions: async (pluginConfig, context) => {
const {env} = context;
if (!env.CURSEFORGE_PAT.length) {
throw AggregateError('No Curseforge personal access token provided');
}
},
success: async (pluginConfig, context) => {
const {nextRelease} = context;
const version = nextRelease.version;
const changelog = escapeControlCharacters(nextRelease.notes);
const {env} = context;
const curseforgeToken = env.CURSEFORGE_PAT;
const formData = new FormData();
formData.append('metadata', `{
"changelog": "${changelog}",
"changelogType": "markdown",
"displayName": "Create: Mob Spawners ${version}",
"gameVersions": [9990, 10150, 7498],
"releaseType": "release"
}`);
formData.append('file', fs.createReadStream(`./build/reobfJar/create-mob-spawners-1.20.1-${version}.jar`));
let headers = formData.getHeaders();
headers['X-Api-Token'] = curseforgeToken;
await axios.post('https://minecraft.curseforge.com/api/projects/1175578/upload-file', formData, {
headers: headers,
});
}
}