1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const net_1 = require("@xmcl/net");
|
11 | const parser = __importStar(require("fast-html-parser"));
|
12 | const index_1 = require("./index");
|
13 | var ForgeWebPage;
|
14 | (function (ForgeWebPage) {
|
15 | |
16 |
|
17 |
|
18 | function parse(content) {
|
19 | const dom = parser.parse(content);
|
20 | const selected = dom.querySelector(".elem-active");
|
21 | const mcversion = selected.text;
|
22 | return {
|
23 | timestamp: "",
|
24 | mcversion,
|
25 | versions: dom.querySelector(".download-list").querySelector("tbody").querySelectorAll("tr")
|
26 | .map((e) => {
|
27 | const links = e.querySelector(".download-links").childNodes
|
28 | .filter((elem) => elem.tagName === "li")
|
29 | .map((elem) => {
|
30 | elem = elem.removeWhitespace();
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const tooltipInfo = elem.querySelector(".info-tooltip");
|
38 | const url = tooltipInfo.querySelector("a") || elem.querySelector("a");
|
39 |
|
40 | const href = url.attributes.href.trim();
|
41 | const matched = /forge-.+-.+-(\w+)\.\w+/.exec(href);
|
42 | let name = "", sha1 = "", md5 = "";
|
43 | if (matched) {
|
44 | name = matched[1];
|
45 | }
|
46 | if (!name) {
|
47 | throw new Error(`Cannot determine name for forge url "${href}". Maybe the forge webisite changed?`);
|
48 | }
|
49 | try {
|
50 | md5 = tooltipInfo.childNodes[1].text.trim();
|
51 | sha1 = tooltipInfo.childNodes[4].text.trim();
|
52 | }
|
53 | catch (_a) {
|
54 | console.warn(`Error during fetching the sha1 and md5 for the forge "${href}". The result might be wrong.`);
|
55 | }
|
56 | const isSha1 = /\b([a-f0-9]{40})\b/i;
|
57 | const isMd5 = /\b[a-f0-9]{32}\b/i;
|
58 | if (!isMd5.test(md5.trim())) {
|
59 | console.warn(`Illegal Md5 for "${href}": ${md5}`);
|
60 | md5 = "";
|
61 | }
|
62 | if (!isSha1.test(sha1.trim())) {
|
63 | console.warn(`Illegal Sha1 for "${href}": ${sha1}`);
|
64 | sha1 = "";
|
65 | }
|
66 | return {
|
67 | name,
|
68 | md5,
|
69 | sha1,
|
70 | path: href,
|
71 | };
|
72 | });
|
73 | const downloadVersionElem = e.querySelector(".download-version");
|
74 | let version;
|
75 | let type = "common";
|
76 | const icon = downloadVersionElem.querySelector("i");
|
77 | if (icon) {
|
78 | if (icon.classNames.indexOf("promo-recommended") !== -1) {
|
79 | type = "recommended";
|
80 | }
|
81 | else if (icon.classNames.indexOf("promo-latest") !== -1) {
|
82 | type = "latest";
|
83 | }
|
84 | else if (icon.classNames.indexOf("fa-bug") !== -1) {
|
85 | type = "buggy";
|
86 | }
|
87 | version = downloadVersionElem.firstChild.text.trim();
|
88 | }
|
89 | else {
|
90 | version = downloadVersionElem.text.trim();
|
91 | }
|
92 | const installer = links.find((l) => l.name === "installer");
|
93 | const universal = links.find((l) => l.name === "universal");
|
94 | const changelog = links.find((l) => l.name === "changelog");
|
95 | const installerWin = links.find((l) => l.name === "installer-win");
|
96 | const source = links.find((l) => l.name === "source");
|
97 | const launcher = links.find((l) => l.name === "launcher");
|
98 | const mdk = links.find((l) => l.name === "mdk");
|
99 | if (installer === undefined || universal === undefined) {
|
100 | throw new Error("Cannot parse forge web since it missing installer and universal jar info.");
|
101 | }
|
102 | const result = {
|
103 | version,
|
104 | "date": e.querySelector(".download-time").text.trim(),
|
105 | changelog,
|
106 | installer,
|
107 | mdk,
|
108 | universal,
|
109 | source,
|
110 | launcher,
|
111 | "installer-win": installerWin,
|
112 | "mcversion": mcversion,
|
113 | type,
|
114 | };
|
115 | return result;
|
116 | }),
|
117 | };
|
118 | }
|
119 | ForgeWebPage.parse = parse;
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | async function getWebPage(option = {}) {
|
129 | const mcversion = option.mcversion || "";
|
130 | const url = mcversion === "" ? "http://files.minecraftforge.net/maven/net/minecraftforge/forge/index.html" : `http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_${mcversion}.html`;
|
131 | const page = await net_1.getIfUpdate(url, parse, option.fallback);
|
132 | return page;
|
133 | }
|
134 | ForgeWebPage.getWebPage = getWebPage;
|
135 | let Version;
|
136 | (function (Version) {
|
137 | function to(webPageVersion) {
|
138 | return {
|
139 | universal: webPageVersion.universal,
|
140 | installer: webPageVersion.installer,
|
141 | mcversion: webPageVersion.mcversion,
|
142 | version: webPageVersion.version,
|
143 | };
|
144 | }
|
145 | Version.to = to;
|
146 | })(Version = ForgeWebPage.Version || (ForgeWebPage.Version = {}));
|
147 | })(ForgeWebPage = exports.ForgeWebPage || (exports.ForgeWebPage = {}));
|
148 | index_1.ForgeInstaller.VersionMeta = index_1.ForgeInstaller.VersionMeta || {};
|
149 | index_1.ForgeInstaller.VersionMeta.from = ForgeWebPage.Version.to;
|
150 |
|
\ | No newline at end of file |