mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-14 12:00:19 +08:00
unify 3 status endpoints and move status fetches to oasst_api_client
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { withRole } from "src/lib/auth";
|
||||
|
||||
/**
|
||||
* Returns the message stats.
|
||||
*/
|
||||
const handler = withRole("admin", async (req, res) => {
|
||||
const statsRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/stats/`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-API-Key": process.env.FASTAPI_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
const stats = await statsRes.json();
|
||||
|
||||
res.status(statsRes.status).json(stats);
|
||||
});
|
||||
|
||||
export default handler;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { withRole } from "src/lib/auth";
|
||||
import { oasstApiClient } from "src/lib/oasst_api_client";
|
||||
|
||||
/**
|
||||
* Returns tasks availability, stats, and tree manager stats.
|
||||
*/
|
||||
const handler = withRole("admin", async (req, res) => {
|
||||
const dummy_user = {
|
||||
id: "__dummy_user__",
|
||||
display_name: "Dummy User",
|
||||
auth_method: "local",
|
||||
};
|
||||
const tasksAvailabilityData = await oasstApiClient.fetch_tasks_availability(dummy_user);
|
||||
const statsData = await oasstApiClient.fetch_stats();
|
||||
const treeManagerData = await oasstApiClient.fetch_tree_manager();
|
||||
|
||||
const status = {
|
||||
tasksAvailability: tasksAvailabilityData,
|
||||
stats: statsData,
|
||||
treeManager: treeManagerData,
|
||||
};
|
||||
|
||||
res.status(200).json(status);
|
||||
});
|
||||
|
||||
export default handler;
|
||||
@@ -1,24 +0,0 @@
|
||||
import { withRole } from "src/lib/auth";
|
||||
|
||||
/**
|
||||
* Returns result of tasks availability query using a dummy user.
|
||||
*/
|
||||
const handler = withRole("admin", async (req, res) => {
|
||||
const tasksAvailabilityRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/tasks/availability`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-API-Key": process.env.FASTAPI_KEY,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: "__dummy_user__",
|
||||
display_name: "Dummy User",
|
||||
auth_method: "local",
|
||||
}),
|
||||
});
|
||||
const tasksAvailability = await tasksAvailabilityRes.json();
|
||||
|
||||
res.status(tasksAvailabilityRes.status).json(tasksAvailability);
|
||||
});
|
||||
|
||||
export default handler;
|
||||
@@ -1,18 +0,0 @@
|
||||
import { withRole } from "src/lib/auth";
|
||||
|
||||
/**
|
||||
* Returns tree manager stats.
|
||||
*/
|
||||
const handler = withRole("admin", async (req, res) => {
|
||||
const treeManagerRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/stats/tree_manager`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-API-Key": process.env.FASTAPI_KEY,
|
||||
},
|
||||
});
|
||||
const treeManager = await treeManagerRes.json();
|
||||
|
||||
res.status(treeManagerRes.status).json(treeManager);
|
||||
});
|
||||
|
||||
export default handler;
|
||||
Reference in New Issue
Block a user