patch_collector: typescript

This commit is contained in:
2024-11-30 11:17:11 +01:00
parent 5778deaa92
commit e6d771a3a5
4 changed files with 33 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
const { MongoClient, ServerApiVersion } = require("mongodb");
import { MongoClient } from "mongodb";
main()
@@ -18,24 +18,18 @@ async function fetchLatestPatch() {
const url = "https://ddragon.leagueoflegends.com/api/versions.json"
const patchDataResponse = await fetch(url);
const patchData = await patchDataResponse.json();
const patch = patchData[0];
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`, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
})
const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@mongo:27017`)
await client.connect()
return client
}
async function compareLatestSavedPatch(client, newPatch, newDate) {
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()

View File

@@ -10,6 +10,9 @@
"license": "ISC",
"dependencies": {
"mongodb": "^6.10.0"
},
"devDependencies": {
"@types/node": "^22.10.1"
}
},
"node_modules/@mongodb-js/saslprep": {
@@ -21,6 +24,16 @@
"sparse-bitfield": "^3.0.3"
}
},
"node_modules/@types/node": {
"version": "22.10.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz",
"integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.20.0"
}
},
"node_modules/@types/webidl-conversions": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
@@ -137,6 +150,13 @@
"node": ">=14"
}
},
"node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true,
"license": "MIT"
},
"node_modules/webidl-conversions": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",

View File

@@ -11,5 +11,8 @@
"description": "",
"dependencies": {
"mongodb": "^6.10.0"
},
"devDependencies": {
"@types/node": "^22.10.1"
}
}

View File

@@ -0,0 +1,6 @@
{
"compilerOptions": {
"types": ["node"]
},
}