mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-07 11:17:38 +08:00
Refactor fetch and post to use axios
Fix set_label id missing in payload use frontend_message_id pre-commit Refactor api fetcher/poster to axios create lint Remove string literal for path Revert oasst_api_client.ts Fix warning httpStatusCode OasstError optional parameter Refactor remove api base url for local api Lint add blank line
This commit is contained in:
@@ -6,7 +6,7 @@ import { useSession } from "next-auth/react";
|
||||
import { useEffect } from "react";
|
||||
import { getAdminLayout } from "src/components/Layout";
|
||||
import { UserMessagesCell } from "src/components/UserMessagesCell";
|
||||
import poster from "src/lib/poster";
|
||||
import { post } from "src/lib/api";
|
||||
import prisma from "src/lib/prismadb";
|
||||
import useSWRMutation from "swr/mutation";
|
||||
|
||||
@@ -31,7 +31,7 @@ const ManageUser = ({ user }) => {
|
||||
}, [router, session, status]);
|
||||
|
||||
// Trigger to let us update the user's role. Triggers a toast when complete.
|
||||
const { trigger } = useSWRMutation("/api/admin/update_user", poster, {
|
||||
const { trigger } = useSWRMutation("/api/admin/update_user", post, {
|
||||
onSuccess: () => {
|
||||
toast({
|
||||
title: "User Role Updated",
|
||||
|
||||
@@ -5,7 +5,7 @@ import prisma from "src/lib/prismadb";
|
||||
* Update's the user's data in the database. Accessible only to admins.
|
||||
*/
|
||||
const handler = withRole("admin", async (req, res) => {
|
||||
const { id, role } = JSON.parse(req.body);
|
||||
const { id, role } = req.body;
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
|
||||
@@ -5,7 +5,7 @@ import prisma from "src/lib/prismadb";
|
||||
|
||||
const handler = withoutRole("banned", async (req, res) => {
|
||||
// Parse out the local task ID and the interaction contents.
|
||||
const { id: frontendId, reason } = await JSON.parse(req.body);
|
||||
const { id: frontendId, reason } = req.body;
|
||||
|
||||
const registeredTask = await prisma.registeredTask.findUniqueOrThrow({ where: { id: frontendId } });
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ import { withoutRole } from "src/lib/auth";
|
||||
*/
|
||||
const handler = withoutRole("banned", async (req, res, token) => {
|
||||
// Parse out the local message_id, and the interaction contents.
|
||||
const { message_id, label_map, text } = await JSON.parse(req.body);
|
||||
|
||||
const { message_id, label_map, text } = req.body;
|
||||
const interactionRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/text_labels`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -15,7 +15,7 @@ import prisma from "src/lib/prismadb";
|
||||
*/
|
||||
const handler = withoutRole("banned", async (req, res, token) => {
|
||||
// Parse out the local task ID and the interaction contents.
|
||||
const { id: frontendId, content, update_type } = await JSON.parse(req.body);
|
||||
const { id: frontendId, content, update_type } = req.body;
|
||||
|
||||
// Accept the task so that we can complete it, this will probably go away soon.
|
||||
const registeredTask = await prisma.registeredTask.findUniqueOrThrow({ where: { id: frontendId } });
|
||||
|
||||
@@ -5,14 +5,14 @@ import { getDashboardLayout } from "src/components/Layout";
|
||||
import { MessageLoading } from "src/components/Loading/MessageLoading";
|
||||
import { MessageTableEntry } from "src/components/Messages/MessageTableEntry";
|
||||
import { MessageWithChildren } from "src/components/Messages/MessageWithChildren";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import { get } from "src/lib/api";
|
||||
import useSWR from "swr";
|
||||
|
||||
const MessageDetail = ({ id }) => {
|
||||
const backgroundColor = useColorModeValue("white", "gray.700");
|
||||
const [parent, setParent] = useState(null);
|
||||
|
||||
const { isLoading: isLoadingParent } = useSWR(id ? `/api/messages/${id}/parent` : null, fetcher, {
|
||||
const { isLoading: isLoadingParent } = useSWR(id ? `/api/messages/${id}/parent` : null, get, {
|
||||
onSuccess: (data) => {
|
||||
setParent(data);
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import Head from "next/head";
|
||||
import { useEffect, useState } from "react";
|
||||
import { getDashboardLayout } from "src/components/Layout";
|
||||
import { MessageTable } from "src/components/Messages/MessageTable";
|
||||
import fetcher from "src/lib/fetcher";
|
||||
import { get } from "src/lib/api";
|
||||
import { Message } from "src/types/Conversation";
|
||||
import useSWRImmutable from "swr/immutable";
|
||||
|
||||
@@ -14,11 +14,11 @@ const MessagesDashboard = () => {
|
||||
const [messages, setMessages] = useState<Message[]>(null);
|
||||
const [userMessages, setUserMessages] = useState<Message[]>(null);
|
||||
|
||||
const { isLoading: isLoadingAll, mutate: mutateAll } = useSWRImmutable("/api/messages", fetcher, {
|
||||
const { isLoading: isLoadingAll, mutate: mutateAll } = useSWRImmutable("/api/messages", get, {
|
||||
onSuccess: setMessages,
|
||||
});
|
||||
|
||||
const { isLoading: isLoadingUser, mutate: mutateUser } = useSWRImmutable(`/api/messages/user`, fetcher, {
|
||||
const { isLoading: isLoadingUser, mutate: mutateUser } = useSWRImmutable(`/api/messages/user`, get, {
|
||||
onSuccess: setUserMessages,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user