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,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