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