Skip to content

Commit

Permalink
Merge pull request #25 from YasaitoriOvO/develop
Browse files Browse the repository at this point in the history
✨ 新增 API 接口
  • Loading branch information
cfdxkk authored Jan 27, 2025
2 parents 9863567 + f01792b commit 7388552
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 48 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/check-for-env-theft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
run: |
git fetch origin ${{ github.base_ref }}
- name: Search for process.env in diff
- name: Search for process.env in code diff
run: |
if git diff --name-only --diff-filter=AM origin/${{ github.base_ref }} | xargs grep -E "process.env"; then
echo "Found process.env in changed files, check failed!"
# Check for changes in code (not just file names)
if git diff origin/${{ github.base_ref }} --unified=0 | grep -E "^\+.*process.env"; then
echo "Found process.env in changed code, check failed!"
exit 1
else
echo "No process.env found in changed files, check passed!"
echo "No process.env found in changed code, check passed!"
fi
30 changes: 23 additions & 7 deletions src/controller/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
updateOrCreateUserInfoService,
updateOrCreateUserSettingsService,
updateUserEmailService,
userExistsCheckService,
userLoginService,
userRegistrationService,
getUserInvitationCodeService,
Expand All @@ -34,9 +33,10 @@ import {
checkUserHave2FAByUUIDService,
createUserEmailAuthenticatorService,
sendUserEmailAuthenticatorService,
checkEmailAuthenticatorVerificationCodeService,
deleteUserEmailAuthenticatorService,
sendDeleteUserEmailAuthenticatorService,
checkUserExistsByUIDService,
userEmailExistsCheckService,
} from '../service/UserService.js'
import { koaCtx, koaNext } from '../type/koaTypes.js'
import {
Expand All @@ -63,7 +63,8 @@ import {
UpdateOrCreateUserSettingsRequestDto,
UpdateUserEmailRequestDto,
UpdateUserPasswordRequestDto,
UserExistsCheckRequestDto,
UserEmailExistsCheckRequestDto,
UserExistsCheckByUIDRequestDto,
UserLoginRequestDto,
UserLogoutResponseDto,
UserRegistrationRequestDto
Expand Down Expand Up @@ -286,14 +287,14 @@ export const checkUserHave2FAByUUIDController = async (ctx: koaCtx, next: koaNex
* 检查一个用户是否存在
* @param ctx context
* @param next context
* @return UserExistsCheckResultDto 检查结果,如果用户邮箱已存在或查询失败则 exists: true
* @return UserEmailExistsCheckResultDto 检查结果,如果用户邮箱已存在或查询失败则 exists: true
*/
export const userExistsCheckController = async (ctx: koaCtx, next: koaNext) => {
export const userEmailExistsCheckController = async (ctx: koaCtx, next: koaNext) => {
const email = ctx.query.email as string
const userExistsCheckData: UserExistsCheckRequestDto = {
const userEmailExistsCheckData: UserEmailExistsCheckRequestDto = {
email: email || '',
}
ctx.body = await userExistsCheckService(userExistsCheckData)
ctx.body = await userEmailExistsCheckService(userEmailExistsCheckData)
await next()
}

Expand Down Expand Up @@ -409,6 +410,21 @@ export const getUserInfoByUidController = async (ctx: koaCtx, next: koaNext) =>
await next()
}

/**
* 获取用户是否存在
* @param ctx context
* @param next context
* @return UserExistsCheckResultDto 检查结果
*/
export const userExistsCheckByUIDController = async (ctx: koaCtx, next: koaNext) => {
const uid = ctx.query.uid as string
const userExistsCheckRequest: UserExistsCheckByUIDRequestDto = {
uid: uid ? parseInt(uid, 10) : -1,
}
ctx.body = await checkUserExistsByUIDService(userExistsCheckRequest)
await next()
}

/**
* 校验用户 token
* // DELETE: 顺便给用户加上UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,42 @@ export type UserLoginResponseDto = {
authenticatorType?: 'email' | 'totp' | 'none';
}

/**
* 检查用户是否存在的请求参数
*/
export type UserExistsCheckByUIDRequestDto = {
/** 用户 UID */
uid: number;
}

/**
* 检查用户是否存在的请求响应
*/
export type UserExistsCheckByUIDResponseDto = {
/** 执行结果,程序执行成功,返回 true,程序执行失败,返回 false */
success: boolean;
/** 用户存在返回 true,不存在返回 false */
exists: boolean;
/** 附加的文本消息 */
message?: string;
}

/**
* 验证用户邮箱是否存在提交的参数
*/
export type UserExistsCheckRequestDto = {
export type UserEmailExistsCheckRequestDto = {
/** 用户邮箱 */
email: string;
}

/**
* 验证用户邮箱是否已经存在的返回参数
*/
export type UserExistsCheckResponseDto = {
export type UserEmailExistsCheckResponseDto = {
/** 执行结果,程序执行成功,返回 true,程序执行失败,返回 false */
success: boolean;
/** 用户存在或者查询失败(悲观)都会返回 true,不存在返回 false */
exists: boolean; // WARN: 用户已存在或查询失败时都会返回 true
exists: boolean; // WARN: 用户已存在或查询失败(悲观)时都会返回 true,用以防止用户意外的使用重复邮箱注册。
/** 附加的文本消息 */
message?: string;
}
Expand Down
File renamed without changes.
20 changes: 18 additions & 2 deletions src/controller/VideoController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { approvePendingReviewVideoService, deleteVideoByKvidService, getPendingReviewVideoService, getThumbVideoService, getVideoByKvidService, getVideoByUidRequestService, getVideoCoverUploadSignedUrlService, getVideoFileTusEndpointService, searchVideoByKeywordService, searchVideoByVideoTagIdService, updateVideoService } from '../service/VideoService.js'
import { approvePendingReviewVideoService, checkVideoExistByKvidService, deleteVideoByKvidService, getPendingReviewVideoService, getThumbVideoService, getVideoByKvidService, getVideoByUidRequestService, getVideoCoverUploadSignedUrlService, getVideoFileTusEndpointService, searchVideoByKeywordService, searchVideoByVideoTagIdService, updateVideoService } from '../service/VideoService.js'
import { koaCtx, koaNext } from '../type/koaTypes.js'
import { ApprovePendingReviewVideoRequestDto, DeleteVideoRequestDto, GetVideoByKvidRequestDto, GetVideoByUidRequestDto, GetVideoFileTusEndpointRequestDto, SearchVideoByKeywordRequestDto, SearchVideoByVideoTagIdRequestDto, UploadVideoRequestDto } from './VideoControllerDto.js'
import { ApprovePendingReviewVideoRequestDto, CheckVideoExistRequestDto, DeleteVideoRequestDto, GetVideoByKvidRequestDto, GetVideoByUidRequestDto, GetVideoFileTusEndpointRequestDto, SearchVideoByKeywordRequestDto, SearchVideoByVideoTagIdRequestDto, UploadVideoRequestDto } from './VideoControllerDto.js'

/**
* 上传视频
Expand Down Expand Up @@ -47,6 +47,22 @@ export const getThumbVideoController = async (ctx: koaCtx, next: koaNext) => {
await next()
}

/**
* 根据 kvid 获取视频是否存在
* @param ctx context
* @param next context
* @returns 获取视频是否存在
*/
export const checkVideoExistController = async (ctx: koaCtx, next: koaNext) => {
const videoId = ctx.query.videoId as string
const CheckVideoExistRequestDto: CheckVideoExistRequestDto = {
videoId: videoId ? parseInt(videoId, 10) : -1, // WARN -1 means you can't find any video
}
const getVideoByKvidResponse = await checkVideoExistByKvidService(CheckVideoExistRequestDto)
ctx.body = getVideoByKvidResponse
await next()
}

/**
* 根据 kvid 获取视频详细信息
* @param ctx context
Expand Down
20 changes: 20 additions & 0 deletions src/controller/VideoControllerDto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ export type GetVideoByKvidResponseDto = {
};
}

/**
* 根据视频 ID (KVID) 检查视频是否存在的请求参数
*/
export type CheckVideoExistRequestDto = {
/** 视频 ID (KVID) */
videoId: number;
}

/**
* 根据视频 ID (KVID) 检查视频是否存在的请求响应
*/
export type CheckVideoExistResponseDto = {
/** 是否请求成功 */
success: boolean;
/** 附加的文本消息 */
message?: string;
/** 视频是否存在 */
exist: boolean;
}

/**
* 从 UID 获取视频的请求参数
*/
Expand Down
File renamed without changes.
13 changes: 10 additions & 3 deletions src/route/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
updateOrCreateUserSettingsController,
updateUserEmailController,
updateUserPasswordController,
userExistsCheckController,
userEmailExistsCheckController,
userLoginController,
userLogoutController,
userRegistrationController,
Expand All @@ -40,9 +40,10 @@ import {
sendUserEmailAuthenticatorController,
deleteUserEmailAuthenticatorController,
sendDeleteUserEmailAuthenticatorController,
userExistsCheckByUIDController,
} from '../controller/UserController.js'
import { adminDeleteVideoCommentController, cancelVideoCommentDownvoteController, cancelVideoCommentUpvoteController, deleteSelfVideoCommentController, emitVideoCommentController, emitVideoCommentDownvoteController, emitVideoCommentUpvoteController, getVideoCommentListByKvidController } from '../controller/VideoCommentController.js'
import { approvePendingReviewVideoController, deleteVideoByKvidController, getPendingReviewVideoController, getThumbVideoController, getVideoByKvidController, getVideoByUidController, getVideoCoverUploadSignedUrlController, getVideoFileTusEndpointController, searchVideoByKeywordController, searchVideoByVideoTagIdController, updateVideoController } from '../controller/VideoController.js'
import { approvePendingReviewVideoController, checkVideoExistController, deleteVideoByKvidController, getPendingReviewVideoController, getThumbVideoController, getVideoByKvidController, getVideoByUidController, getVideoCoverUploadSignedUrlController, getVideoFileTusEndpointController, searchVideoByKeywordController, searchVideoByVideoTagIdController, updateVideoController } from '../controller/VideoController.js'
import { createVideoTagController, getVideoTagByTagIdController, searchVideoTagController } from '../controller/VideoTagController.js'

const router = new Router()
Expand Down Expand Up @@ -128,7 +129,7 @@ router.get('/user/checkUserHave2FAByUUID', checkUserHave2FAByUUIDController) //
// https://localhost:9999/user/checkUserHave2FAByUUID
// cookie: uuid, token

router.get('/user/existsCheck', userExistsCheckController) // 注册用户时检查用户是否存在
router.get('/user/existsCheck', userEmailExistsCheckController) // 注册用户时检查用户邮箱是否存在
// https://localhost:9999/user/existsCheck?email=xxxxxxx

router.post('/user/update/email', updateUserEmailController) // 更新用户邮箱
Expand Down Expand Up @@ -188,6 +189,9 @@ router.post('/user/self', getSelfUserInfoController) // 获取当前登录的用
router.get('/user/info', getUserInfoByUidController) // 根据 uid 获取用户信息
// https://localhost:9999/user/info?uid=10

router.get('/user/exists', userExistsCheckByUIDController) // 检查用户是否存在
// https://localhost:9999/user/exists?uid=10

router.get('/user/check', checkUserTokenController) // 根据 uid, token 校验用户
// https://localhost:9999/user/check
// cookie: uid, token
Expand Down Expand Up @@ -329,6 +333,9 @@ router.post('/video/upload', updateVideoController) // 上传视频
router.get('/video/home', getThumbVideoController) // 获取首页视频
// https://localhost:9999/video/home

router.get('/video/exists', checkVideoExistController) // 根据视频 ID (KVID) 检查视频是否存在
// https://localhost:9999/video/exists?videoId=1

router.get('/video', getVideoByKvidController) // 根据视频 ID (KVID) 获取视频的数据
// https://localhost:9999/video?videoId=1
// cookie: uid, token (optional, if have it will try to record the video browsing history)
Expand Down
Loading

0 comments on commit 7388552

Please sign in to comment.