diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-04-29 16:52:19 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-04-29 16:52:19 +0200 |
commit | 9a521f8f0fd99eed39157b741fc4f890c0fee334 (patch) | |
tree | 1daaf643440461a6cea01e90305756b5a8aa32b5 | |
parent | d577ecfaf32ba404bbf7ee4e8821f0a9d7cee9e1 (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.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[]; +} |