diff options
-rw-r--r-- | index.ts | 31 | ||||
-rw-r--r-- | types.ts | 11 |
2 files changed, 38 insertions, 4 deletions
@@ -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)); @@ -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[]; +} |