-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubmission.js
83 lines (72 loc) · 2.32 KB
/
submission.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const {v4: uuidv4} = require('uuid');
const GithubHelper = require('./github');
const Submission = class Submission {
constructor(pkg, uuid, msgid) {
this.pkg = pkg;
if (uuid) {
this.uuid = uuid;
} else {
this.uuid = uuidv4();
}
this.discord_id = msgid;
}
setDiscord(msgid) {
this.discord_id = msgid;
}
async getGitHubRelease() {
const extensions = {
"switch": [".nro"],
"wiiu": [".rpx", ".elf"],
};
let consoleExtensions = extensions[this.pkg.console];
if (consoleExtensions === undefined) {
console.warn("[Approval] WARNING: Unsupported console on package" +
`${this.pkg.package} - "${this.pkg.console}"?`);
consoleExtensions = [".elf"];
}
const hasGoodAsset = this.pkg.assets.some(asset =>
asset.type === 'zip' ||
consoleExtensions.some(ext =>
asset.data.endsWith(ext)
)
);
if (hasGoodAsset) return;
var gh = new GithubHelper();
var releases = await gh.getReleases(this.pkg.info.url, '.zip');
if (releases === undefined) {
//no releases
return;
}
let release = releases.find(release =>
release.name.includes(this.pkg.console)
)
if (release !== undefined && release.browser_download_url !== undefined) {
this.pkg.assets.push({
type: 'zip',
url: release.browser_download_url,
zip: [{path: '/**', dest:'/', type: 'update'}]
});
return;
}
let foundBinary = false;
for (const ext of consoleExtensions) {
let binRelease = await gh.getRelease(this.pkg.info.url, ext);
if (binRelease !== null && binRelease !== undefined) {
this.pkg.assets.push({
type: 'update',
format: 'url',
//TODO spec usage seems a touch inconsistent
url: binRelease,
data: binRelease,
dest: `/${this.pkg.console}/${this.pkg.package}/${this.pkg.package}${ext}`
});
foundBinary = true;
break;
}
};
if (!foundBinary) {
throw new Error(`Could not find ${this.pkg.console} zip or binary-like assets (${consoleExtensions.join()}) on GitHub release!`);
}
} //getGitHubRelease()
} //class Submission
module.exports = Submission;