From 2f09fcabe400ca2b96f4625517e01c6a184a17bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Fri, 6 May 2022 23:10:16 +0800 Subject: [PATCH] Feat: AuthRouter & CleanNeteaseCache API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端增加限制访问的路由,后端调整鉴权接口,增加清除网易云缓存接口 --- prisma/schema.prisma | 9 +++ prisma/seed.ts | 15 ++++ src/components/Admin/AddACGM.tsx | 66 +++++++++++++++++ src/components/Admin/RemoveMusicCache.tsx | 62 ++++++++++++++++ src/components/Base/Button.tsx | 23 ++++++ src/components/Layout/Aside.tsx | 1 + src/components/Layout/FrontWrapper.tsx | 7 +- src/components/Layout/FrontWrapperAuth.tsx | 63 ++++++++++++++++ src/index.css | 33 +++++++++ src/index.tsx | 83 ++++++++++++---------- src/pages/admin.tsx | 27 +++++++ src/pages/login.tsx | 15 ++-- src/server/api/admin/netease/clean.ts | 29 ++++++++ src/server/api/auth/login.ts | 40 +++++++++-- src/server/strategy/jwt.strategy.ts | 14 ++-- 15 files changed, 427 insertions(+), 60 deletions(-) create mode 100644 src/components/Admin/AddACGM.tsx create mode 100644 src/components/Admin/RemoveMusicCache.tsx create mode 100644 src/components/Base/Button.tsx create mode 100644 src/components/Layout/FrontWrapperAuth.tsx create mode 100644 src/pages/admin.tsx create mode 100644 src/server/api/admin/netease/clean.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 586824e..c3a9a2c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,6 +7,15 @@ datasource db { url = env("DB_URL") } +model User { + id String @id @default(cuid()) + name String @unique + email String @unique + password String + created_at DateTime @default(now()) + updated_at DateTime? +} + model ACGM { id Int @id @default(autoincrement()) title String? diff --git a/prisma/seed.ts b/prisma/seed.ts index e15a241..b5e113f 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -24,6 +24,13 @@ const songs: Prisma.ACGMCreateInput[] = [ bangumi: "这个美术部有问题", music_id: 435288259 }, + { + title: "みずきのテーマ", + artist: "吟", + album: "この美術部には問題がある! オリジナルサウンドトラックCD vol.1", + bangumi: "这个美术部有问题", + music_id: 435288260 + }, { title: "伝える勇気があったなら", artist: "吟", @@ -85,6 +92,14 @@ async function main() { }); } + await prisma.user.create({ + data: { + name: "Paul", + email: "dreamer_paul@126.com", + password: "123456", + } + }); + console.log(`Seeding finished.`); } diff --git a/src/components/Admin/AddACGM.tsx b/src/components/Admin/AddACGM.tsx new file mode 100644 index 0000000..2cfec40 --- /dev/null +++ b/src/components/Admin/AddACGM.tsx @@ -0,0 +1,66 @@ +// React +import React from "react"; +import { useRequest } from "ahooks"; +import useStat from "@/hooks/useStat"; + + +// UI +import Button from "@/components/Base/Button"; + + +// Tool +import addMusicRequest from "@/server/api/admin/acgm/add"; + + +// Interface +import { MouseEvent, ChangeEvent } from "react"; + + +// Components +function AddACGM() { + const { loading, run } = useRequest( + (params) => addMusicRequest({ + query: params + }), + { + manual: true, + onSuccess: (data) => { + console.log(data); + } + } + ); + + const [input, setInput] = useStat({ + id: "", + bangumi: "" + }); + + const onSubmit = (ev: MouseEvent) => { + ev.preventDefault(); + + run(input); + } + + const onInputChange = (ev: ChangeEvent) => { + setInput({ [ev.target.name]: ev.target.value }); + } + + return ( +
+ +
+ ) +} + +export default AddACGM; diff --git a/src/components/Admin/RemoveMusicCache.tsx b/src/components/Admin/RemoveMusicCache.tsx new file mode 100644 index 0000000..82e29b2 --- /dev/null +++ b/src/components/Admin/RemoveMusicCache.tsx @@ -0,0 +1,62 @@ +// React +import React from "react"; +import { useRequest } from "ahooks"; +import useStat from "@/hooks/useStat"; + + +// UI +import Button from "@/components/Base/Button"; + + +// Tool +import cleanCacheRequest from "@/server/api/admin/netease/clean"; + + +// Interface +import { MouseEvent, ChangeEvent } from "react"; + + +// Components +function RemoveMusicCache() { + const { loading, run } = useRequest( + (params) => cleanCacheRequest({ + query: params + }), + { + manual: true, + onSuccess: (data) => { + console.log(data); + } + } + ); + + const [input, setInput] = useStat({ + id: "" + }); + + const onSubmit = (ev: MouseEvent) => { + ev.preventDefault(); + + run(input); + } + + const onInputChange = (ev: ChangeEvent) => { + setInput({ [ev.target.name]: ev.target.value }); + } + + return ( +
+ +
+ ) +} + +export default RemoveMusicCache; diff --git a/src/components/Base/Button.tsx b/src/components/Base/Button.tsx new file mode 100644 index 0000000..c8a59e4 --- /dev/null +++ b/src/components/Base/Button.tsx @@ -0,0 +1,23 @@ +// React +import React from "react"; + + +// Interface +interface ButtonProps { + loading?: boolean + children: React.ReactNode + + onClick?: React.MouseEventHandler +} + + +// Component +function Button({ loading = false, children, onClick }: ButtonProps) { + return ( + + ) +} + +export default Button; diff --git a/src/components/Layout/Aside.tsx b/src/components/Layout/Aside.tsx index 0de4d45..f133abf 100644 --- a/src/components/Layout/Aside.tsx +++ b/src/components/Layout/Aside.tsx @@ -47,6 +47,7 @@ function Aside() { 随机动漫音乐 哔哩哔哩小窗 必应每日壁纸 + {profile.name && 轻管理} diff --git a/src/components/Layout/FrontWrapper.tsx b/src/components/Layout/FrontWrapper.tsx index 09547e0..66b6c6c 100644 --- a/src/components/Layout/FrontWrapper.tsx +++ b/src/components/Layout/FrontWrapper.tsx @@ -1,11 +1,9 @@ // React import React, { useEffect, useLayoutEffect } from "react"; -import useGlobalData from "@/hooks/useGlobalData"; import { useLocation } from "react-router-dom"; // Components -import GlobalContext from "@/components/GlobalContext"; import Aside from "@/components/Layout/Aside"; import Footer from "@/components/Layout/Footer"; @@ -20,7 +18,6 @@ interface FrontWrapperProps { // Components function FrontWrapper(props: FrontWrapperProps) { const location = useLocation(); - let [globalData, setGlobalData] = useGlobalData(); useEffect(() => { const name = import.meta.env.PAUL_SITENAME; @@ -38,11 +35,11 @@ function FrontWrapper(props: FrontWrapperProps) { }, [location.pathname]); return ( - + <>