fix: 修复了一堆API错误,并顺手添加了OSS API
This commit is contained in:
@@ -11,9 +11,9 @@ import {
|
||||
DrawerTitle,
|
||||
} from "@/components/ui/drawer"
|
||||
import { useState } from "react";
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { toast } from "sonner";
|
||||
import { ApiError } from "next/dist/server/api-utils";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
|
||||
interface CreateUserEditorProps {
|
||||
children: React.ReactNode;
|
||||
@@ -26,7 +26,7 @@ export function CreateUserEditor({ children, onRefresh }: CreateUserEditorProps)
|
||||
event.preventDefault();
|
||||
const formData = new FormData(event.currentTarget);
|
||||
try {
|
||||
await AdminApi.user.create({
|
||||
await AdminAPI.createUser({
|
||||
username: formData.get("username")?.toString() || null,
|
||||
nickname: formData.get("nickname")?.toString() || null,
|
||||
email: formData.get("email")?.toString() || null,
|
||||
|
||||
@@ -17,7 +17,6 @@ import { Label } from "@/components/ui/label"
|
||||
import { useUser } from "@/hooks/admin/user/use-user";
|
||||
import { User } from "@/lib/types/user";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
Alert,
|
||||
@@ -27,6 +26,7 @@ import {
|
||||
import { AlertCircle } from "lucide-react";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
|
||||
export function UserInfoEditor({
|
||||
onClose,
|
||||
@@ -50,7 +50,7 @@ export function UserInfoEditor({
|
||||
}) => {
|
||||
try {
|
||||
// setSaveLoading(true);
|
||||
const res = await AdminApi.user.update(userId, user);
|
||||
const res = await AdminAPI.updateUser(userId, user);
|
||||
if (res) {
|
||||
toast.success("保存成功");
|
||||
onUserUpdate(res);
|
||||
@@ -69,7 +69,7 @@ export function UserInfoEditor({
|
||||
const handleRemove = async (userId: string) => {
|
||||
try {
|
||||
// setRemoveLoading(true);
|
||||
await AdminApi.user.remove(userId, true);
|
||||
await AdminAPI.removeUser(userId, true);
|
||||
toast.success("注销成功");
|
||||
onUserSoftDelete(userId);
|
||||
onClose();
|
||||
@@ -85,7 +85,7 @@ export function UserInfoEditor({
|
||||
const handleSetPassword = async (userId: string, password: string) => {
|
||||
try {
|
||||
// setSetPasswordLoading(true);
|
||||
await AdminApi.user.setPassword(userId, password);
|
||||
await AdminAPI.setUserPassword(userId, password);
|
||||
toast.success("密码修改成功");
|
||||
setPasswordDialogOpen(false);
|
||||
} catch (error) {
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { BlogPermission } from "@/lib/types/Blog.Permission.enum";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { BlogPermissionCheckBoxs } from "./BlogPermissionCheckBoxs";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
|
||||
interface AddBlogProps {
|
||||
children: React.ReactNode;
|
||||
@@ -35,7 +35,7 @@ export default function AddBlog({ children, onRefresh }: AddBlogProps) {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const res = await AdminApi.web.blog.create({
|
||||
const res = await AdminAPI.createBlog({
|
||||
...blog,
|
||||
});
|
||||
if (res) {
|
||||
@@ -62,7 +62,7 @@ export default function AddBlog({ children, onRefresh }: AddBlogProps) {
|
||||
<DialogTrigger asChild>
|
||||
{children}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogContent className="sm:max-w-100">
|
||||
<DialogHeader>
|
||||
<DialogTitle>添加博客</DialogTitle>
|
||||
<DialogDescription>
|
||||
|
||||
@@ -14,12 +14,12 @@ import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { toast } from "sonner"
|
||||
import { AdminApi } from "@/lib/api"
|
||||
import useSWR from "swr"
|
||||
import { ApiError } from "next/dist/server/api-utils"
|
||||
import { BlogPermissionCheckBoxs } from "./BlogPermissionCheckBoxs"
|
||||
import { BlogPermission } from "@/lib/types/Blog.Permission.enum"
|
||||
import { SetPasswordDialog } from "./SetPasswordDialog"
|
||||
import { AdminAPI } from "@/lib/api/client"
|
||||
|
||||
interface BlogEditProps {
|
||||
id: string;
|
||||
@@ -31,7 +31,7 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const { data: blog, mutate } = useSWR(
|
||||
open ? `/api/admin/web/blog/${id}` : null,
|
||||
() => AdminApi.web.blog.get(id),
|
||||
() => AdminAPI.getBlog(id),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
@@ -43,7 +43,7 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
||||
const handleSubmit = async () => {
|
||||
if (!blog) return;
|
||||
try {
|
||||
await AdminApi.web.blog.update(id, {
|
||||
await AdminAPI.updateBlog(id, {
|
||||
title: blog.title,
|
||||
description: blog.description,
|
||||
contentUrl: blog.contentUrl,
|
||||
@@ -59,7 +59,7 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
await AdminApi.web.blog.remove(id);
|
||||
await AdminAPI.removeBlog(id);
|
||||
toast.success("删除成功")
|
||||
setOpen(false);
|
||||
onRefresh();
|
||||
@@ -73,7 +73,7 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
||||
<DialogTrigger asChild>
|
||||
{children}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogContent className="sm:max-w-100">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑博客</DialogTitle>
|
||||
<DialogDescription>
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function BlogTable({ blogs, error, onRefresh }: BlogTableProps) {
|
||||
}
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[100px]">Id</TableHead>
|
||||
<TableHead className="w-25">Id</TableHead>
|
||||
<TableHead>标题</TableHead>
|
||||
<TableHead>描述</TableHead>
|
||||
<TableHead>文章URL</TableHead>
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
import { base62 } from "@/lib/utils";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
@@ -32,7 +32,7 @@ export function SetPasswordDialog({ id, children }: SetPasswordDialogProps) {
|
||||
return toast.error('请输入密码');
|
||||
}
|
||||
|
||||
await AdminApi.web.blog.setPassword(id, password).then(() => {
|
||||
await AdminAPI.setBlogPassword(id, password).then(() => {
|
||||
toast.success('修改成功');
|
||||
setOpen(false);
|
||||
}).catch(e => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { list, UserListParams, UserListResponse } from '@/lib/api/admin/user'
|
||||
import { AdminAPI } from '@/lib/api/client'
|
||||
import { UserListParams, UserListResponse } from '@/lib/api/endpoints/admin.client'
|
||||
import { useCallback } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import useSWR from 'swr'
|
||||
@@ -8,7 +9,7 @@ import useSWR from 'swr'
|
||||
export function useUserList(params?: UserListParams) {
|
||||
const { data, error, isLoading, mutate } = useSWR<UserListResponse>(
|
||||
['/api/admin/user', params],
|
||||
() => list(params),
|
||||
() => AdminAPI.listUsers(params),
|
||||
{
|
||||
onError: (e) => {
|
||||
toast.error(`${e.message || e}`)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
import { User } from "@/lib/types/user";
|
||||
import { toast } from "sonner";
|
||||
import useSWR from "swr";
|
||||
@@ -6,7 +6,7 @@ import useSWR from "swr";
|
||||
export function useUser(userId: string) {
|
||||
const { data, error, isLoading, mutate } = useSWR<User>(
|
||||
['/api/admin/user', userId],
|
||||
() => AdminApi.user.get(userId),
|
||||
() => AdminAPI.getUser(userId),
|
||||
{
|
||||
revalidateOnReconnect: false,
|
||||
revalidateIfStale: false,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { AdminApi } from "@/lib/api";
|
||||
import { AdminAPI } from "@/lib/api/client";
|
||||
import { useCallback } from "react";
|
||||
import { toast } from "sonner";
|
||||
import useSWR from "swr";
|
||||
@@ -8,7 +8,7 @@ import useSWR from "swr";
|
||||
export function useBlogList() {
|
||||
const { data, error, isLoading, mutate } = useSWR(
|
||||
['/admin/web/blog'],
|
||||
() => AdminApi.web.blog.list(),
|
||||
() => AdminAPI.listBlogs(),
|
||||
{
|
||||
onError: (e) => {
|
||||
toast.error(`${e.message || e}`)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useOssSts } from "@/hooks/oss/use-oss-sts";
|
||||
import { StsToken } from "@/lib/api/oss";
|
||||
import { StsToken } from "@/lib/api/endpoints/oss.client";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function useOssStore(options: { onStsTokenDataChanged?: (data: StsToken | undefined) => void; } = {}) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// import { OssApi } from "@/lib/api";
|
||||
import { OSSAPI } from "@/lib/api/client";
|
||||
import { toast } from "sonner";
|
||||
import useSWR from "swr";
|
||||
|
||||
export function useOssSts() {
|
||||
const { data: stsTokenData, isLoading, error, mutate } = useSWR(
|
||||
'/api/oss/sts',
|
||||
// () => OssApi.getStsToken(),
|
||||
() => OSSAPI.getStsToken(),
|
||||
{
|
||||
shouldRetryOnError: false,
|
||||
// refreshInterval: 59 * 60 * 1000,
|
||||
|
||||
@@ -48,4 +48,5 @@ export async function clientFetch<T = unknown>(
|
||||
export * as AuthAPI from './endpoints/auth.client'
|
||||
export * as UserAPI from './endpoints/user.client'
|
||||
export * as SmsAPI from './endpoints/sms.client'
|
||||
export * as AdminAPI from './endpoints/admin.client'
|
||||
export * as AdminAPI from './endpoints/admin.client'
|
||||
export * as OSSAPI from './endpoints/oss.client'
|
||||
13
apps/frontend/lib/api/endpoints/oss.client.ts
Normal file
13
apps/frontend/lib/api/endpoints/oss.client.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { clientFetch } from "../client";
|
||||
|
||||
export interface StsToken {
|
||||
AccessKeyId: string;
|
||||
AccessKeySecret: string;
|
||||
Expiration: string;// ISO 8601 格式
|
||||
SecurityToken: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export async function getStsToken() {
|
||||
return clientFetch<StsToken>('/api/oss/sts');
|
||||
}
|
||||
Reference in New Issue
Block a user