Lint and format
This commit is contained in:
10
patch_detector/.prettierrc
Normal file
10
patch_detector/.prettierrc
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
16
patch_detector/eslint.config.js
Normal file
16
patch_detector/eslint.config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'eslint/config'
|
||||
import js from '@eslint/js'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import prettier from 'eslint-config-prettier'
|
||||
|
||||
export default defineConfig([
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
prettier,
|
||||
{
|
||||
rules: {
|
||||
semi: 'off',
|
||||
'prefer-const': 'error'
|
||||
}
|
||||
}
|
||||
])
|
||||
@@ -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() {}
|
||||
|
||||
1430
patch_detector/package-lock.json
generated
1430
patch_detector/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,13 @@
|
||||
"name": "patch_detector",
|
||||
"version": "1.0.0",
|
||||
"main": "index.ts",
|
||||
"type": "commonjs",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint --fix .",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check ."
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -13,7 +17,15 @@
|
||||
"mongodb": "^6.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@types/node": "^22.10.1",
|
||||
"tsx": "^4.19.2"
|
||||
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
||||
"@typescript-eslint/parser": "^8.53.1",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"prettier": "^3.8.0",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.53.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
},
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user