Skip to content

Commit 60b8e8c

Browse files
Hokori23upupming
andauthored
feat: 完成用户页面和后台管理页面 (#8)
* feat: 添加用户编辑信息接口 * feat: 前端登陆注册Material-UI & 路由守卫 & 用户中心 * feat: admin 开始开发 * feat: 后端 Upload & Video接口 * feat: 前端 用户中心 & Upload获取Authorization&Policy等 * feat: upyun配置 * feat: working on admin * chore: 线上网址配置 * fix: 后端 用户修改接口无需密码 * fix: 修正后端生成signature错误 * fix: 修正前端登陆状态保存异常 * fix: 修正UI配色 * fix: 修正axios处理异常状态码 * feat: tools库 * feat: 用户 -- 头像上传 & 简介修改 & 粉丝关注 * feat: 修复样式小问题 * feat: 修复登陆状态 * feat: 后端 Video模块 * feat: 后端 checkValidUser中间件 * fix: 修正后端upload类型检测 * fix: 统一在reducers内进行localStorage登陆状态的变更 * fix: 修正App-tabs配色 * feat: /user页面 视频上传功能 * feat: token添加uid * feat: 登出功能 * feat: 优化写法 * fix: 首页登录态失效跳转 & axios登录态失效处理 * feat: 后端 admin crud 路由 * feat: 路由 for react-admin * feat: BDPlayer添加作者信息 * feat: 单独播放页面 & 404页面 * fix: tinyfix * fix: 修复缺失module * feat: 完成后台管理页面 * chore: package-lock.json * fix: 修复注册页样式 * feat: 其他用户信息页面 * fix: UI优化 * feat: 后台主页提示信息 * fix: 修复变量错误 * fix: 修复变量错误 Co-authored-by: upupming <[email protected]>
1 parent c909e8c commit 60b8e8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3978
-292
lines changed

.vscode/settings.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616
"typescriptreact"
1717
],
1818
"cSpell.words": [
19+
"DIALOGCONTENT",
20+
"DIALOGSTATUS",
21+
"DIALOGTITLE",
22+
"Datagrid",
23+
"LOGSTATUS",
24+
"SNACKCONTENT",
25+
"SNACKSTATUS",
1926
"Swiper",
27+
"USERINFO",
2028
"Vercel",
2129
"douyin",
30+
"filemd",
31+
"fontsource",
2232
"gitee",
2333
"immer",
2434
"standardjs",
25-
"techtrainingcamp"
35+
"techtrainingcamp",
36+
"upyun"
2637
],
2738
"[less]": {
2839
"editor.formatOnSave": true,

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ npm run start
3737
- Storybook
3838
- Less
3939

40+
后台管理路由:http://localhost:3000/admin/
41+
4042
### 后端
4143

4244
存放于文件夹 [backend](backend)

backend/package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dotenv": "^8.2.0",
2828
"express": "~4.16.1",
2929
"express-jwt": "^6.0.0",
30+
"express-sequelize-crud": "^6.1.5",
3031
"jsonwebtoken": "^8.5.1",
3132
"moment": "^2.29.0",
3233
"mysql2": "^2.1.0",

backend/src/action/VideoAction.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* eslint-disable @typescript-eslint/promise-function-async */
2+
import { User, Video } from 'models'
3+
4+
/**
5+
* 添加视频
6+
* @param { Video } video
7+
*/
8+
const Create = async (video: Video) => {
9+
return await video.save()
10+
}
11+
12+
/**
13+
* 遍历视频
14+
*/
15+
const Retrieve__All = () => {
16+
return Video.findAll({
17+
include: [User],
18+
})
19+
}
20+
21+
/**
22+
* 查询某用户的视频
23+
* @param { number } uid
24+
*/
25+
const Retrieve__UID = (uid: number) => {
26+
return Video.findAll({
27+
where: {
28+
uid,
29+
},
30+
})
31+
}
32+
33+
/**
34+
* 通过ID查询某视频
35+
* @param { number } id
36+
*/
37+
const Retrieve__ID = (id: number) => {
38+
return Video.findOne({
39+
where: {
40+
id,
41+
},
42+
include: [User],
43+
})
44+
}
45+
46+
/**
47+
* 删除视频
48+
* @param { number } id
49+
*/
50+
const Delete = (id: number): Promise<number> => {
51+
return Video.destroy({
52+
where: {
53+
id,
54+
},
55+
})
56+
}
57+
58+
export default {
59+
Create,
60+
Retrieve__All,
61+
Retrieve__ID,
62+
Retrieve__UID,
63+
Delete,
64+
}

backend/src/action/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import UserAction from './UserAction'
2-
export { UserAction }
3-
export default { User: UserAction }
2+
import VideoAction from './VideoAction'
3+
export { UserAction, VideoAction }
4+
export default { User: UserAction, Video: VideoAction }

backend/src/app.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import express from 'express'
22

3-
import { UserRouter, TestRouter } from '@routes'
4-
import { errorHandler, checkJWT } from '@middleware'
5-
3+
import { UserRouter, TestRouter, VideoRouter, UploadRouter } from '@routes'
4+
import { errorHandler, checkJWT, checkValidUser } from '@middleware'
5+
import crud, { sequelizeCrud } from 'express-sequelize-crud'
6+
import {
7+
Live,
8+
LiveComment,
9+
Tag,
10+
User,
11+
UserLikeVideo,
12+
UserPlayVideo,
13+
Video,
14+
VideoTag,
15+
Following,
16+
} from '@models'
617
const app = express()
718

819
app.use(express.json())
@@ -12,12 +23,25 @@ app.use(express.urlencoded({ extended: false }))
1223
* JWT中间件
1324
*/
1425
app.use(checkJWT)
26+
app.use(checkValidUser)
1527

1628
/**
1729
* 业务路由
1830
*/
1931
app.use('/api/test', TestRouter)
2032
app.use('/api/user', UserRouter)
33+
app.use('/api/video', VideoRouter)
34+
app.use('/api/upload', UploadRouter)
35+
36+
app.use(crud('/api/admin/user', sequelizeCrud(User)))
37+
app.use(crud('/api/admin/video', sequelizeCrud(Video)))
38+
app.use(crud('/api/admin/user-like-video', sequelizeCrud(UserLikeVideo)))
39+
app.use(crud('/api/admin/user-play-video', sequelizeCrud(UserPlayVideo)))
40+
app.use(crud('/api/admin/live', sequelizeCrud(Live)))
41+
app.use(crud('/api/admin/live-comment', sequelizeCrud(LiveComment)))
42+
app.use(crud('/api/admin/tag', sequelizeCrud(Tag)))
43+
app.use(crud('/api/admin/video-tag', sequelizeCrud(VideoTag)))
44+
app.use(crud('/api/admin/following', sequelizeCrud(Following)))
2145

2246
// 包底错误处理中间件
2347
app.use(errorHandler)

backend/src/bd7.config.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ const sequelizeOptions: Options = {
3535

3636
const devConfig = {
3737
port: 8003,
38-
host:
39-
// "https://api.hokori.online" ||
40-
'http://localhost/',
38+
host: 'http://localhost/',
4139
cryptoConfig: {
4240
// 每次分段加密的字符串最大长度(优先度高于cryptCount字段)
4341
onceCryptLength: 5,
@@ -66,6 +64,14 @@ const devConfig = {
6664
// 时区
6765
timezone: '+08:00',
6866
},
67+
upyunConfig: {
68+
operator: process.env.UPYUN_OPERATOR as string,
69+
secret: process.env.UPYUN_SECRET as string,
70+
bucket: process.env.UPYUN_BUCKET as string,
71+
domainName: process.env.UPYUN_DOMAINNAME as string,
72+
imgPath: 'bd7/image/',
73+
videoPath: 'bd7/video/',
74+
},
6975
// 12个小时
7076
tokenExpiredTime: '12h',
7177
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UserAction } from '@action'
2+
import { ROUTER_WHITE_LIST } from '@utils'
3+
export default async (req: any, res, next) => {
4+
if (!ROUTER_WHITE_LIST.every((url) => !req.url.match(url))) {
5+
console.log('white list')
6+
return next()
7+
}
8+
const user = await UserAction.Retrieve__Safely('username', req.auth.username)
9+
if (!user) {
10+
res.status(401).end()
11+
}
12+
next()
13+
}

backend/src/middleware/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import errorHandler from './errorHandler'
22
import checkJWT from './checkJWT'
3-
export { errorHandler, checkJWT }
3+
import checkValidUser from './checkValidUser'
4+
export { errorHandler, checkJWT, checkValidUser }
45
export default {
56
errorHandler,
67
checkJWT,
8+
checkValidUser,
79
}

backend/src/models/Following.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export enum Followed {
88
}
99

1010
class Following extends Model {
11+
id!: number
1112
uid_from!: number
1213
uid_to!: number
1314
followed!: Followed
@@ -17,10 +18,15 @@ class Following extends Model {
1718

1819
Following.init(
1920
{
21+
id: {
22+
type: DataTypes.INTEGER.UNSIGNED,
23+
primaryKey: true,
24+
autoIncrement: true,
25+
comment: '自增字段(主键)',
26+
},
2027
uid_from: {
2128
type: DataTypes.INTEGER.UNSIGNED,
2229
comment: 'follow 发起者',
23-
primaryKey: true,
2430
references: {
2531
model: User,
2632
key: 'id',
@@ -30,7 +36,6 @@ Following.init(
3036
uid_to: {
3137
type: DataTypes.INTEGER.UNSIGNED,
3238
comment: '被 follow 的人',
33-
primaryKey: true,
3439
references: {
3540
model: User,
3641
key: 'id',

backend/src/models/User.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export enum Gender {
1010
class User extends Model {
1111
public id!: number | null
1212
public username!: string
13-
public password!: string
13+
public password?: string
1414
public profile?: string
1515
public gender!: Gender
1616
public avatar_url?: string

backend/src/models/UserLikeVideo.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum Liked {
99
}
1010

1111
class UserLikeVideo extends Model {
12+
id!: number
1213
uid!: number
1314
vid!: number
1415
liked!: Liked
@@ -18,10 +19,15 @@ class UserLikeVideo extends Model {
1819

1920
UserLikeVideo.init(
2021
{
22+
id: {
23+
type: DataTypes.INTEGER.UNSIGNED,
24+
primaryKey: true,
25+
autoIncrement: true,
26+
comment: '自增字段(主键)',
27+
},
2128
uid: {
2229
type: DataTypes.INTEGER.UNSIGNED,
2330
comment: '用户 id',
24-
primaryKey: true,
2531
references: {
2632
model: User,
2733
key: 'id',
@@ -30,7 +36,6 @@ UserLikeVideo.init(
3036
vid: {
3137
type: DataTypes.INTEGER.UNSIGNED,
3238
comment: '视频 id',
33-
primaryKey: true,
3439
references: {
3540
model: Video,
3641
key: 'id',

backend/src/models/UserPlayVideo.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import User from './User'
44
import Video from './Video'
55

66
class UserPlayVideo extends Model {
7+
id!: number
78
uid!: number
89
vid!: number
910
play_count!: number
@@ -13,10 +14,15 @@ class UserPlayVideo extends Model {
1314

1415
UserPlayVideo.init(
1516
{
17+
id: {
18+
type: DataTypes.INTEGER.UNSIGNED,
19+
primaryKey: true,
20+
autoIncrement: true,
21+
comment: '自增字段(主键)',
22+
},
1623
uid: {
1724
type: DataTypes.INTEGER.UNSIGNED,
1825
comment: '用户 id',
19-
primaryKey: true,
2026
references: {
2127
model: User,
2228
key: 'id',
@@ -25,7 +31,6 @@ UserPlayVideo.init(
2531
vid: {
2632
type: DataTypes.INTEGER.UNSIGNED,
2733
comment: '视频 id',
28-
primaryKey: true,
2934
references: {
3035
model: Video,
3136
key: 'id',

backend/src/models/VideoTag.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum VideoTagLinked {
99
}
1010

1111
class VideoTag extends Model {
12+
id!: number
1213
vid!: number
1314
tid!: number
1415
linked!: VideoTagLinked
@@ -18,10 +19,15 @@ class VideoTag extends Model {
1819

1920
VideoTag.init(
2021
{
22+
id: {
23+
type: DataTypes.INTEGER.UNSIGNED,
24+
primaryKey: true,
25+
autoIncrement: true,
26+
comment: '自增字段(主键)',
27+
},
2128
vid: {
2229
type: DataTypes.INTEGER.UNSIGNED,
2330
comment: '视频 id',
24-
primaryKey: true,
2531
references: {
2632
model: Video,
2733
key: 'id',
@@ -30,7 +36,6 @@ VideoTag.init(
3036
tid: {
3137
type: DataTypes.INTEGER.UNSIGNED,
3238
comment: '标签 id',
33-
primaryKey: true,
3439
references: {
3540
model: Tag,
3641
key: 'id',

backend/src/models/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import UserPlayVideo from './UserPlayVideo'
88
import Live from './Live'
99
import LiveComment from './LiveComment'
1010

11+
/**
12+
* Video : User
13+
* N : 1
14+
*/
15+
Video.belongsTo(User, {
16+
foreignKey: 'uid',
17+
onDelete: 'SET NULL',
18+
})
19+
User.hasMany(Video, {
20+
sourceKey: 'id',
21+
foreignKey: 'uid',
22+
})
23+
1124
export {
1225
User,
1326
Following,

0 commit comments

Comments
 (0)