Files
jenna-mcp/src/server/routes/darmasaba_route.ts
amaliadwiy 7587b3ac54 upd: mcp pengaduan
Deskripsi:
- database pengaduan
- api categori pengaduan > create list update hapus
- api pengaduan > create pengaduan dan history, update status dan create history

No Issues
2025-10-27 17:40:56 +08:00

248 lines
6.9 KiB
TypeScript

import Elysia, { t } from "elysia";
import { prisma } from "../lib/prisma";
const url = "https://cld-dkr-makuro-seafile.wibudev.com/api2"
const TOKEN = "fa49bf1774cad2ec89d2882ae2c6ac1f5d7df445"
const REPO_ID = "de64ff3c-0081-45f3-a5a6-6c799a098649"
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/${REPO_ID}/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/${REPO_ID}/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",
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/${REPO_ID}/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",
description: "get content of file in darmasaba/<dir>/<file_name>"
}
})
.get("/list-pengetahuan-umum", async () => {
const res = await fetch(url + `/repos/${REPO_ID}/dir/?p=${encodeURIComponent('darmasaba/pengetahuan-umum')}`, {
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: "list-pengetahuan-umum",
description: "get list of files in darmasaba/pengetahuan-umum"
}
})
.get("/pengetahuan-umum/:file_name", async ({ params }) => {
const { file_name } = params
const res = await fetch(url + `/repos/${REPO_ID}/file/?p=${encodeURIComponent('darmasaba/pengetahuan-umum/' + 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({
file_name: t.String()
}),
detail: {
summary: "pengetahuan-umum",
description: "get content of file in darmasaba/pengetahuan-umum/<file_name>"
}
})
.post("/buat-pengaduan", async ({ body }) => {
const { jenis_laporan, name, phone, detail } = body
// await prisma.pengaduan.create({
// data: {
// jenis_laporan,
// detail,
// name,
// phone
// }
// })
return `
${JSON.stringify(body)}
laporan sudah diterima dan akan segera di tindak lanjuti`
}, {
body: t.Object({
jenis_laporan: t.String({ minLength: 1, error: "jenis laporan harus diisi" }),
name: t.String({ minLength: 1, error: "name harus diisi" }),
phone: t.String({ minLength: 1, error: "phone harus diisi" }),
detail: t.String({ minLength: 1, error: "detail harus diisi" })
}),
detail: {
summary: "buat-pengaduan atau pelaporan",
description: `tool untuk membuat pengaduan atau pelaporan warga kepada desa darmasaba`
}
})
.post("/status-pengaduan", async ({ body }) => {
const { name, phone } = body
// const pengaduan = await prisma.pengaduan.findMany({
// where: {
// name,
// phone
// }
// })
// return pengaduan
}, {
body: t.Object({
name: t.String(),
phone: t.String()
}),
detail: {
summary: "lihat status pengaduan",
description: "melikat status pengaduan dari user"
}
})
export default DarmasabaRoute