tamabahan
This commit is contained in:
@@ -2,6 +2,7 @@ import Elysia, { t } from "elysia";
|
|||||||
|
|
||||||
const url = "https://cld-dkr-makuro-seafile.wibudev.com/api2"
|
const url = "https://cld-dkr-makuro-seafile.wibudev.com/api2"
|
||||||
const TOKEN = "fa49bf1774cad2ec89d2882ae2c6ac1f5d7df445"
|
const TOKEN = "fa49bf1774cad2ec89d2882ae2c6ac1f5d7df445"
|
||||||
|
const REPO_ID = "de64ff3c-0081-45f3-a5a6-6c799a098649"
|
||||||
|
|
||||||
const DarmasabaRoute = new Elysia({
|
const DarmasabaRoute = new Elysia({
|
||||||
prefix: "/darmasaba",
|
prefix: "/darmasaba",
|
||||||
@@ -35,7 +36,7 @@ const DarmasabaRoute = new Elysia({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.get("/ls", async () => {
|
.get("/ls", async () => {
|
||||||
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/dir/?p=${encodeURIComponent('darmasaba')}`, {
|
const res = await fetch(url + `/repos/${REPO_ID}/dir/?p=${encodeURIComponent('darmasaba')}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + TOKEN
|
Authorization: "Bearer " + TOKEN
|
||||||
}
|
}
|
||||||
@@ -58,12 +59,13 @@ const DarmasabaRoute = new Elysia({
|
|||||||
}, {
|
}, {
|
||||||
detail: {
|
detail: {
|
||||||
summary: "ls",
|
summary: "ls",
|
||||||
description: "get list of dir in darmasaba"
|
description: "get list of dir in darmasaba",
|
||||||
}
|
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.get("/ls/:dir", async ({ params }) => {
|
.get("/ls/:dir", async ({ params }) => {
|
||||||
const { dir } = params
|
const { dir } = params
|
||||||
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/dir/?p=${encodeURIComponent('darmasaba/' + dir)}`, {
|
const res = await fetch(url + `/repos/${REPO_ID}/dir/?p=${encodeURIComponent('darmasaba/' + dir)}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + TOKEN
|
Authorization: "Bearer " + TOKEN
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,7 @@ const DarmasabaRoute = new Elysia({
|
|||||||
})
|
})
|
||||||
.get("/file/:dir/:file_name", async ({ params }) => {
|
.get("/file/:dir/:file_name", async ({ params }) => {
|
||||||
const { dir, file_name } = params
|
const { dir, file_name } = params
|
||||||
const res = await fetch(url + `/repos/de64ff3c-0081-45f3-a5a6-6c799a098649/file/?p=${encodeURIComponent('darmasaba/' + dir + '/' + file_name)}`, {
|
const res = await fetch(url + `/repos/${REPO_ID}/file/?p=${encodeURIComponent('darmasaba/' + dir + '/' + file_name)}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + TOKEN
|
Authorization: "Bearer " + TOKEN
|
||||||
}
|
}
|
||||||
@@ -126,6 +128,67 @@ const DarmasabaRoute = new Elysia({
|
|||||||
description: "get content of file in darmasaba/<dir>/<file_name>"
|
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>"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
export default DarmasabaRoute
|
export default DarmasabaRoute
|
||||||
|
|||||||
Reference in New Issue
Block a user