-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# prisma | ||
/prisma/migrations | ||
|
||
# build output | ||
/build | ||
|
||
.env | ||
|
||
package-lock.json |
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,28 @@ | ||
{ | ||
"name": "lavalink-api", | ||
"version": "1.0.0", | ||
"description": "lavalink-api for list of lavalink nodes in cloudflare workers", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"@cloudflare/vitest-pool-workers": "0.1.17", | ||
"@cloudflare/workers-types": "4.20240405.0", | ||
"@types/node": "^20.12.5", | ||
"prisma": "5.12.1", | ||
"typescript": "5.4.4", | ||
"vitest": "1.4.0", | ||
"wrangler": "3.48.0" | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "5.12.1", | ||
"@prisma/extension-accelerate": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"deploy": "wrangler deploy -e production", | ||
"dev": "wrangler dev", | ||
"start": "wrangler dev", | ||
"test": "vitest" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,33 @@ | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["driverAdapters"] | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_DATABASE_URL") | ||
} | ||
|
||
model Node { | ||
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 | ||
} | ||
|
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,12 @@ | ||
{ | ||
"apps": [ | ||
{ | ||
"name": "lava-list-api", | ||
"script": "build/index.js", | ||
"node_args": [ | ||
"--enable-source-maps" | ||
], | ||
"restart_delay": 10000 | ||
} | ||
] | ||
} |
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,61 @@ | ||
import { PrismaClient } from '@prisma/client/edge' | ||
import { withAccelerate } from '@prisma/extension-accelerate' | ||
|
||
export interface Env { | ||
DATABASE_URL: string; | ||
} | ||
|
||
|
||
export default { | ||
fetch: async (request: Request, env: Env, ctx: ExecutionContext) => { | ||
try { | ||
|
||
const prisma = new PrismaClient({ | ||
datasourceUrl: env.DATABASE_URL | ||
}).$extends(withAccelerate()); | ||
const url = new URL(request.url); | ||
|
||
if (url.pathname === "/") { | ||
return new Response("Welcome to Lavalink status api", { | ||
headers: { | ||
"Content-Type": "text/plain" | ||
} | ||
}); | ||
} else if (url.pathname === "/ssl-nodes" || url.pathname === "/non-ssl-nodes") { | ||
|
||
const nodes = await prisma.node.findMany({ | ||
where: { | ||
secure: url.pathname === "/ssl-nodes" ? true : false | ||
} | ||
}); | ||
if (nodes.length === 0) { | ||
return new Response("Not Found", { | ||
status: 404, | ||
headers: { | ||
"Content-Type": "text/plain" | ||
} | ||
}); | ||
} | ||
return new Response(JSON.stringify(nodes), { | ||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
}); | ||
} else { | ||
return new Response("Not Found", { | ||
status: 404, | ||
headers: { | ||
"Content-Type": "text/plain" | ||
} | ||
}); | ||
} | ||
} catch (error: any) { | ||
return new Response(error.message || "Internal Server Error", { | ||
status: 500, | ||
headers: { | ||
"Content-Type": "text/plain" | ||
} | ||
}); | ||
} | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"module": "commonjs", | ||
"target": "esnext", | ||
"lib": ["webworker", "dom", "es6"], | ||
"alwaysStrict": true, | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"preserveConstEnums": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"esModuleInterop": true, | ||
"types": ["@cloudflare/workers-types", "@types/node"] | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "dist", "test"] | ||
} |
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,11 @@ | ||
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config"; | ||
|
||
export default defineWorkersConfig({ | ||
test: { | ||
poolOptions: { | ||
workers: { | ||
wrangler: { configPath: "./wrangler.toml" }, | ||
}, | ||
}, | ||
}, | ||
}); |
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,8 @@ | ||
name = "cloudflare-worker-api" | ||
account_id = "" | ||
main = "src/index.ts" | ||
compatibility_date = "2024-04-07" | ||
compatibility_flags = ["nodejs_compat"] | ||
|
||
|
||
[env.production.vars] |