Lint and format
This commit is contained in:
@@ -1,60 +1,61 @@
|
||||
import { MongoClient } from "mongodb";
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
main()
|
||||
|
||||
async function main() {
|
||||
const client = await connectToDatabase()
|
||||
const newPatch = await fetchLatestPatch()
|
||||
|
||||
console.log("Latest patch is: " + newPatch)
|
||||
const client = await connectToDatabase()
|
||||
const newPatch = await fetchLatestPatch()
|
||||
|
||||
const newDate = new Date()
|
||||
if(!(await compareLatestSavedPatch(client, newPatch, newDate))) {
|
||||
downloadAssets()
|
||||
}
|
||||
console.log('Latest patch is: ' + newPatch)
|
||||
|
||||
await client.close()
|
||||
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;
|
||||
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
|
||||
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
||||
if(process.env.MONGO_URI != undefined && process.env.MONGO_URI != null && process.env.MONGO_URI != "") {
|
||||
uri = process.env.MONGO_URI
|
||||
}
|
||||
const client = new MongoClient(uri)
|
||||
await client.connect()
|
||||
return client
|
||||
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
||||
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
||||
if (
|
||||
process.env.MONGO_URI != undefined &&
|
||||
process.env.MONGO_URI != null &&
|
||||
process.env.MONGO_URI != ''
|
||||
) {
|
||||
uri = process.env.MONGO_URI
|
||||
}
|
||||
const client = new MongoClient(uri)
|
||||
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 == null) {
|
||||
console.log("No previous patch recorded in database.")
|
||||
} else {
|
||||
console.log("Latest patch in database is: " + latestPatch.patch)
|
||||
}
|
||||
|
||||
if(latestPatch == null || latestPatch.patch != newPatch) {
|
||||
await patches.insertOne({patch:newPatch, date:newDate})
|
||||
return false
|
||||
}
|
||||
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()
|
||||
|
||||
return true
|
||||
if (latestPatch == null) {
|
||||
console.log('No previous patch recorded in database.')
|
||||
} else {
|
||||
console.log('Latest patch in database is: ' + latestPatch.patch)
|
||||
}
|
||||
|
||||
if (latestPatch == null || latestPatch.patch != newPatch) {
|
||||
await patches.insertOne({ patch: newPatch, date: newDate })
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async function downloadAssets() {
|
||||
|
||||
}
|
||||
async function downloadAssets() {}
|
||||
|
||||
Reference in New Issue
Block a user