aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-04-29 16:52:19 +0200
committerlonkaars <loek@pipeframe.xyz>2021-04-29 16:52:19 +0200
commit9a521f8f0fd99eed39157b741fc4f890c0fee334 (patch)
tree1daaf643440461a6cea01e90305756b5a8aa32b5
parentd577ecfaf32ba404bbf7ee4e8821f0a9d7cee9e1 (diff)
Added api response types
Still need to fetch the direct download link and token from the optifine website and then it's done :tada:
-rw-r--r--index.ts31
-rw-r--r--types.ts11
2 files changed, 38 insertions, 4 deletions
diff --git a/index.ts b/index.ts
index cdb1572..2c95d06 100644
--- a/index.ts
+++ b/index.ts
@@ -1,7 +1,7 @@
import puppeteer from 'puppeteer';
import cheerio from 'cheerio';
-import { OptifineVersion } from './types';
+import * as types from './types';
var browser = await puppeteer.launch();
var page = await browser.newPage();
@@ -14,14 +14,15 @@ await browser.close();
var $ = cheerio.load(html);
-var versions: OptifineVersion[] = [];
+var versions: types.OptifineVersion[] = [];
$("td.content span.downloads .downloadLine").each((i, el) => {
var downloadLinkPre = $(el).find(".colMirror a").attr("href");
- var version: OptifineVersion = {
+ var version: types.OptifineVersion = {
name: $(el).find(".colFile").text(),
minecraft: downloadLinkPre.match(/1\.\d{1,2}(\.\d{1,2})?/)[0],
forge: $(el).find(".colForge").text().toLowerCase().replace("forge", "").trim(),
date: $(el).find(".colDate").text(),
+ preview: downloadLinkPre.toLowerCase().includes("preview"),
download: {
link: downloadLinkPre,
token: "",
@@ -31,5 +32,27 @@ $("td.content span.downloads .downloadLine").each((i, el) => {
versions.push(version);
});
-console.log(versions);
+var minecraftVersions = {};
+var latest: types.OptifineVersion;
+var latestPre: types.OptifineVersion;
+for(var version of versions) {
+ if (typeof minecraftVersions[version.minecraft] === "undefined")
+ minecraftVersions[version.minecraft] = [];
+ minecraftVersions[version.minecraft].push(version);
+
+ if (!latest && version.preview == false)
+ latest = version;
+ if (!latestPre && version.preview == true)
+ latestPre = version;
+}
+
+var response: types.APIResponse = {
+ lastUpdate: Date.now(),
+ all: versions,
+ versions: minecraftVersions,
+ latest,
+ latestPre
+}
+
+console.log(JSON.stringify(response));
diff --git a/types.ts b/types.ts
index 5b8d74f..d132df1 100644
--- a/types.ts
+++ b/types.ts
@@ -3,6 +3,7 @@ export interface OptifineVersion {
minecraft: string;
forge: string;
date: string;
+ preview: boolean;
download: OptifineDownload;
}
@@ -11,3 +12,13 @@ export interface OptifineDownload {
filename: string;
token: string;
}
+
+export interface APIResponse {
+ lastUpdate: number;
+ latest: OptifineVersion;
+ latestPre: OptifineVersion;
+ versions: {
+ [key: string]: OptifineVersion[];
+ }
+ all: OptifineVersion[];
+}