feat: add credential routes and mcp manifest

This commit is contained in:
bipproduction
2025-10-08 14:17:06 +08:00
parent 94a8d78fe3
commit 2366710ccd
15 changed files with 801 additions and 18 deletions

View File

@@ -0,0 +1,46 @@
import Elysia, { t } from "elysia";
import { prisma } from "../lib/prisma";
const CredentialRoute = new Elysia({
prefix: "/credential"
})
.post("/create", async (ctx) => {
const { name, value } = ctx.body
const create = await prisma.credential.create({
data: {
name,
value
}
})
return {
message: "success",
create
}
}, {
body: t.Object({
name: t.String(),
value: t.String(),
})
})
.get("/list", async (ctx) => {
const list = await prisma.credential.findMany()
return {
message: "success",
list
}
})
.delete("/rm", async (ctx) => {
const { id } = ctx.body
const rm = await prisma.credential.delete({
where: {
id: id
}
})
}, {
body: t.Object({
id: t.String()
})
})
export default CredentialRoute

View File

@@ -1,8 +0,0 @@
import Elysia from "elysia";
const Dashboard = new Elysia({
prefix: "/dashboard"
})
.get("/apa", () => "Hello World")
export default Dashboard

View File

@@ -0,0 +1,131 @@
import Elysia, { t } from "elysia";
const url = "https://cld-dkr-makuro-seafile.wibudev.com/api2"
const TOKEN = "fa49bf1774cad2ec89d2882ae2c6ac1f5d7df445"
const DarmasabaRoute = new Elysia({
prefix: "/darmasaba",
tags: ["darmasaba"]
})
.get("/repos", async () => {
const res = await fetch(url + "/repos", {
headers: {
Authorization: "Bearer " + TOKEN
}
})
if (!res.ok) {
console.log(res)
return {
message: "Failed to fetch directory"
}
}
const data = await res.json() as { name: string, id: string, type: string }[]
return data.map((v) => {
return {
name: v.name,
id: v.id,
type: v.type
}
})
}, {
detail: {
summary: "/repos",
description: "get list of repositories"
}
})
.get("/ls", async () => {
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/dir/?p=${encodeURIComponent('darmasaba')}`, {
headers: {
Authorization: "Bearer " + TOKEN
}
})
if (!res.ok) {
console.log(res)
return {
message: "Failed to fetch directory"
}
}
const data = await res.json() as { name: string, id: string, type: string }[]
return data.map((v) => {
return {
name: v.name,
id: v.id,
type: v.type
}
})
}, {
detail: {
summary: "/ls",
description: "get list of dir in darmasaba"
}
})
.get("/ls/:dir", async ({ params }) => {
const { dir } = params
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/dir/?p=${encodeURIComponent('darmasaba/' + dir)}`, {
headers: {
Authorization: "Bearer " + TOKEN
}
})
if (!res.ok) {
console.log(res)
return {
message: "Failed to fetch directory"
}
}
const data = await res.json() as { name: string, id: string, type: string }[]
return data.map((v) => {
return {
name: v.name,
id: v.id,
type: v.type
}
})
}, {
params: t.Object({
dir: t.String()
}),
detail: {
summary: "/ls/:dir",
description: "get list of files in darmasaba/<dir>"
}
})
.get("/file/:dir/:file_name", async ({ params }) => {
const { dir, file_name } = params
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/file/?p=${encodeURIComponent('darmasaba/' + dir + '/' + file_name)}`, {
headers: {
Authorization: "Bearer " + TOKEN
}
})
if (!res.ok) {
console.log(res)
return {
message: "Failed to fetch directory"
}
}
const downloadUrl = (await res.text()).replace(/"/g, '');
const resText = await fetch(downloadUrl, {
headers: {
Authorization: "Bearer " + TOKEN
}
})
return resText.text()
}, {
params: t.Object({
dir: t.String(),
file_name: t.String()
}),
detail: {
summary: "/file/:dir/:file_name",
description: "get content of file in darmasaba/<dir>/<file_name>"
}
})
export default DarmasabaRoute