diff --git a/.github/workflows/main .yml b/.github/workflows/main .yml index 0b17cd6..065e3b9 100644 --- a/.github/workflows/main .yml +++ b/.github/workflows/main .yml @@ -24,14 +24,10 @@ jobs: - name: Install Dependencies run: yarn install - - name: Generate Prisma Client - run: npx prisma generate - - name: Run TypeScript Script env: TURSO_DATABASE_URL: ${{ secrets.TURSO_DATABASE_URL }} TURSO_AUTH_TOKEN: ${{ secrets.TURSO_AUTH_TOKEN }} - DATABASE_URL: ${{ secrets.DATABASE_URL }} run: yarn start - name: Commit Changes diff --git a/.hintrc b/.hintrc new file mode 100644 index 0000000..1f14328 --- /dev/null +++ b/.hintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "development" + ], + "hints": { + "typescript-config/consistent-casing": "off" + } +} \ No newline at end of file diff --git a/package.json b/package.json index d92465b..17b6b6f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "lavalink-list", "version": "1.0.0", "description": "A list of free and available public Lavalink nodes with their live status. Feel free to make a pull request!", - "main": "update_nodes.js", + "main": "update_nodes.ts", "scripts": { "start": "npx ts-node update_nodes.ts" }, @@ -10,15 +10,12 @@ "author": "", "license": "ISC", "dependencies": { - "@libsql/client": "^0.8.0", - "@prisma/adapter-libsql": "^5.18.0", - "@prisma/client": "^5.18.0", - "dotenv": "^16.4.5" + "@libsql/client": "^0.8.1", + "dotenv": "^16.4.5", + "ts-node": "^10.9.2" }, "devDependencies": { "@types/node": "^22.5.0", - "prisma": "^5.18.0", - "ts-node": "^10.9.2", "typescript": "^5.5.4" } -} +} \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma deleted file mode 100644 index f2020fe..0000000 --- a/prisma/schema.prisma +++ /dev/null @@ -1,44 +0,0 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? -// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init - -generator client { - provider = "prisma-client-js" - previewFeatures = ["driverAdapters"] -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -model Node { - id String @id @default(cuid()) - authorId String - host String - identifier String @unique - password String - port Int - restVersion String - secure Boolean - isConnected Boolean @default(false) - info Json? - author Json? - memory String? - connections String? - systemLoad String? - cpuCores Int? - uptime String? - cpu String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -model Nodes { - id String @id @default(cuid()) - nodes Json - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} diff --git a/update_nodes.ts b/update_nodes.ts index af34b29..cf70383 100644 --- a/update_nodes.ts +++ b/update_nodes.ts @@ -1,15 +1,13 @@ const fs = require('fs'); -const { PrismaClient } = require('@prisma/client'); -const { PrismaLibSQL } = require('@prisma/adapter-libsql'); const { createClient } = require('@libsql/client'); require('dotenv').config(); +// Initialize the libsql client const libsql = createClient({ url: process.env.TURSO_DATABASE_URL || '', authToken: process.env.TURSO_AUTH_TOKEN, }); -const adapter = new PrismaLibSQL(libsql); // Define types for node objects interface Node { host: string; @@ -37,12 +35,12 @@ function removeDuplicates(data: Node[]): Node[] { // Function to add restVersion if it is missing function addRestVersion(data: Node[]): Node[] { - for (const node of data) { + return data.map(node => { if (!node.restVersion) { node.restVersion = 'v4'; } - } - return data; + return node; + }); } // Load data from nodes.json @@ -67,18 +65,28 @@ if (uniqueData.length < data.length) { // Update database with unique nodes async function updateNodes(nodes: Node[]): Promise { console.log("Updating nodes in database..."); - const prisma = new PrismaClient({ adapter }); - await prisma.$connect(); - // delete all nodes - await prisma.nodes.deleteMany(); - // create new nodes - await prisma.nodes.createMany({ - data: { - nodes: JSON.stringify(nodes) - } - }); - await prisma.$disconnect(); + try { + // Delete all nodes + await libsql.execute("DELETE FROM Node"); + + // Create an array of placeholders and values for batch insert + const placeholders = nodes.map(() => '(?, ?, ?, ?, ?, ?, ?)').join(','); + const values = nodes.flatMap(node => [ + node.host, + node.identifier, + node.password, + node.port, + node.restVersion, + node.secure, + node.authorId, + ]); + + // Insert new nodes in one query + await libsql.execute(`INSERT INTO Node (host, identifier, password, port, restVersion, secure, authorId) VALUES ${placeholders}`, values); + } catch (error) { + console.error("Error updating nodes:", error); + } } // Call updateNodes with uniqueData