mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-15 01:00:53 +08:00
split api into multiple files
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { boolean } from "boolean";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
const handler = async (req, res) => {
|
||||
const token = await getToken({ req });
|
||||
|
||||
// Return nothing if the user isn't registered.
|
||||
if (!token) {
|
||||
res.status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-API-Key": process.env.FASTAPI_KEY,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const messages = await messagesRes.json();
|
||||
|
||||
// Send recieved messages to the client.
|
||||
res.status(200).json(messages);
|
||||
};
|
||||
|
||||
export default handler;
|
||||
@@ -1,4 +1,3 @@
|
||||
import { boolean } from "boolean";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
const handler = async (req, res) => {
|
||||
@@ -11,9 +10,8 @@ const handler = async (req, res) => {
|
||||
}
|
||||
|
||||
//TODO: add params if needed
|
||||
const reqParams = req.query;
|
||||
const params = new URLSearchParams({
|
||||
username: boolean(reqParams.allUsers) ? "" : token.sub,
|
||||
username: token.sub,
|
||||
});
|
||||
|
||||
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages?${params}`, {
|
||||
@@ -3,12 +3,10 @@ import {
|
||||
Box,
|
||||
CircularProgress,
|
||||
HStack,
|
||||
Image,
|
||||
SimpleGrid,
|
||||
Stack,
|
||||
StackDivider,
|
||||
Text,
|
||||
useColorMode,
|
||||
useColorModeValue,
|
||||
} from "@chakra-ui/react";
|
||||
import Head from "next/head";
|
||||
@@ -68,13 +66,13 @@ const MessagesDashboard = () => {
|
||||
const [messages, setMessages] = useState([]);
|
||||
const [userMessages, setUserMessages] = useState([]);
|
||||
|
||||
const { isLoading: isLoadingAll } = useSWRImmutable("/api/messages?allUsers=true", fetcher, {
|
||||
const { isLoading: isLoadingAll } = useSWRImmutable("/api/messages", fetcher, {
|
||||
onSuccess: (data) => {
|
||||
setMessages(data);
|
||||
},
|
||||
});
|
||||
|
||||
const { isLoading: isLoadingUser } = useSWRImmutable(`/api/messages`, fetcher, {
|
||||
const { isLoading: isLoadingUser } = useSWRImmutable(`/api/messages/user`, fetcher, {
|
||||
onSuccess: (data) => {
|
||||
setUserMessages(data);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user