import { MongoClient } from "mongodb"; main() async function main() { const client = await connectToDatabase(); const newPatch = await fetchLatestPatch(); const newDate = new Date() if(!(await compareLatestSavedPatch(client, newPatch, newDate))) { downloadAssets() } await client.close() } async function fetchLatestPatch() { const url = "https://ddragon.leagueoflegends.com/api/versions.json" const patchDataResponse = await fetch(url); const patchData = await patchDataResponse.json(); const patch : string = patchData[0]; return patch; } async function connectToDatabase() { // Create a MongoClient with a MongoClientOptions object to set the Stable API version const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@mongo:27017`) await client.connect() return client } async function compareLatestSavedPatch(client: MongoClient, newPatch : string, newDate : Date) { const database = client.db("patches") const patches = database.collection("patches") const latestPatch = await patches.find().limit(1).sort({date:-1}).next() if(latestPatch.patch != newPatch) { await patches.insertOne({patch:newPatch, date:newDate}) return false } return true } async function downloadAssets() { }