-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update .gitignore and pyproject.toml, add package.json, update prisma…
…/schema.prisma, and modify .github/workflows/main.yml and update_nodes.py
- Loading branch information
Showing
7 changed files
with
126 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"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", | ||
"scripts": { | ||
"start": "ts-node update_nodes.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@libsql/client": "^0.6.0", | ||
"@prisma/adapter-libsql": "^5.13.0", | ||
"@prisma/client": "^5.13.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.12.7", | ||
"prisma": "^5.13.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as fs from 'fs'; | ||
import { PrismaClient } from '@prisma/client'; | ||
import { PrismaLibSQL } from "@prisma/adapter-libsql"; | ||
import { createClient } from "@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; | ||
identifier: string; | ||
password?: string; | ||
port?: number; | ||
restVersion?: string; | ||
secure?: boolean; | ||
authorId?: string; | ||
} | ||
|
||
// Function to remove duplicate nodes | ||
function removeDuplicates(data: Node[]): Node[] { | ||
const seenIdentifiers = new Set<string>(); | ||
const uniqueData: Node[] = []; | ||
for (const node of data) { | ||
const { identifier } = node; | ||
if (!seenIdentifiers.has(identifier)) { | ||
seenIdentifiers.add(identifier); | ||
uniqueData.push(node); | ||
} | ||
} | ||
return uniqueData; | ||
} | ||
|
||
// Function to add restVersion if it is missing | ||
function addRestVersion(data: Node[]): Node[] { | ||
for (const node of data) { | ||
if (!node.restVersion) { | ||
node.restVersion = 'v4'; | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
// Load data from nodes.json | ||
const data: Node[] = JSON.parse(fs.readFileSync('nodes.json', 'utf8')); | ||
|
||
// Add restVersion if it is missing | ||
const dataWithRestVersion = addRestVersion(data); | ||
|
||
// Remove duplicates | ||
const uniqueData = removeDuplicates(dataWithRestVersion); | ||
|
||
// Check if any nodes were removed | ||
if (uniqueData.length < data.length) { | ||
console.log("Duplicate nodes removed."); | ||
|
||
// Save updated data back to nodes.json | ||
fs.writeFileSync('nodes.json', JSON.stringify(uniqueData, null, 4)); | ||
} else { | ||
console.log("No duplicate nodes found."); | ||
} | ||
|
||
// Update database with unique nodes | ||
async function updateNodes(nodes: Node[]): Promise<void> { | ||
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(); | ||
} | ||
|
||
// Call updateNodes with uniqueData | ||
updateNodes(uniqueData) | ||
.then(() => console.log("Nodes updated successfully.")) | ||
.catch(err => console.error("Error updating nodes:", err)); |