diff --git a/.eslintrc.cjs b/.eslintrc.cjs index a3102867..d320b41c 100755 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -130,6 +130,7 @@ module.exports = { "no-labels": "off", "default-case-last": "off", "no-useless-constructor": "off", // private constructor() { } 你跟我说无用? + "no-multiple-empty-lines": ["error", { max: 1, maxEOF: 0, maxBOF: 0 }], "import/order": "off", // 与 VSCode 内置导入排序特性打架。 "import/first": "off", // 与 Vue 特性冲突。 "import/named": "off", // 与 TypeScript 特性冲突。 diff --git a/components/Thumb/ThumbVideo.vue b/components/Thumb/ThumbVideo.vue index 7bfdd526..9f706a55 100755 --- a/components/Thumb/ThumbVideo.vue +++ b/components/Thumb/ThumbVideo.vue @@ -44,7 +44,7 @@
- cover + cover
视频标题
diff --git a/composables/api.ts b/composables/api.ts new file mode 100644 index 00000000..e69de29b diff --git a/composables/api/Common/GetCorrectUri.ts b/composables/api/Common/GetCorrectUri.ts deleted file mode 100644 index 719cc743..00000000 --- a/composables/api/Common/GetCorrectUri.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const getCorrectUri = (): string => { - return environment.production ? "https://rosales.kirakira.moe" : "https://localhost:9999"; -}; diff --git a/composables/api/Common/getCorrectUri.ts b/composables/api/Common/getCorrectUri.ts new file mode 100644 index 00000000..74aa732f --- /dev/null +++ b/composables/api/Common/getCorrectUri.ts @@ -0,0 +1,7 @@ +/** + * 根据当前环境(开发或生产)确定正确的后端地址。 + * @returns 正确的后端地址。 + */ +export default function getCorrectUri() { + return environment.production ? "https://rosales.kirakira.moe" : "https://localhost:9999"; +} diff --git a/composables/api/User/UserController.ts b/composables/api/User/UserController.ts index 52e7373e..d8d53546 100644 --- a/composables/api/User/UserController.ts +++ b/composables/api/User/UserController.ts @@ -1,8 +1,7 @@ -import { get, post } from "../Common"; -import { getCorrectUri } from "../Common/GetCorrectUri"; +import { get, post } from "api/Common"; +import getCorrectUri from "api/Common/getCorrectUri"; import type { UserExistsCheckDataDto, UserExistsCheckResultDto, UserLoginDataDto, UserLoginResultDto, UserRegistrationDataDto, UserRegistrationResultDto } from "./UserControllerDto"; - const BACK_END_URL = getCorrectUri(); const USER_API_URI = `${BACK_END_URL}/user`; diff --git a/composables/api/User/UserControllerDto.d.ts b/composables/api/User/UserControllerDto.d.ts index 6ba81eac..82b6dbc3 100644 --- a/composables/api/User/UserControllerDto.d.ts +++ b/composables/api/User/UserControllerDto.d.ts @@ -1,73 +1,73 @@ /** * 用户注册提交的参数 - * @param username 用户名 - * @param passwordHash 在前端已经 Hash 过一次的的密码 - * @param passwordHint 密码提示 */ export type UserRegistrationDataDto = { + /** 用户名 */ username: string; + /** 在前端已经 Hash 过一次的的密码 */ passwordHash: string; + /** 密码提示 */ passwordHint?: string; }; /** * 用户注册的返回参数 - * @param success 执行结果,程序执行成功,返回 true,程序执行失败,返回 false - * @param uid 用户 ID - * @param token 如果注册成功,则返回一个 token,如果注册失败,则 token 是一个假值(undefined、null 或 '') - * @param message 附加的文本消息 */ export type UserRegistrationResultDto = { + /** 执行结果,程序执行成功,返回 true,程序执行失败,返回 false */ success: boolean; + /** 用户 ID */ uid?: number; + /** 如果注册成功,则返回一个 token,如果注册失败,则 token 是一个假值(undefined、null 或 "") */ token?: string; + /** 附加的文本消息 */ message?: string; }; /** * 用户登录提交的参数 - * @param username 用户名 - * @param passwordHash 在前端已经 Hash 过一次的的密码 */ export type UserLoginDataDto = { + /** 用户名 */ username: string; + /** 在前端已经 Hash 过一次的的密码 */ passwordHash: string; }; /** * 用户登录的返回参数 - * @param success 执行结果,程序执行成功,返回 true,程序执行失败,返回 false - * @param username 用户名 - * @param uid 用户 ID - * @param token 如果登录成功,则返回一个 token,如果登录失败,则 token 是一个假值(undefined、null 或 '') - * @param passwordHint 密码提示 - * @param message 附加的文本消息 */ export type UserLoginResultDto = { + /** 执行结果,程序执行成功,返回 true,程序执行失败,返回 false */ success: boolean; + /** 用户名 */ username?: string; + /** 用户 ID */ uid?: number; + /** 如果登录成功,则返回一个 token,如果登录失败,则 token 是一个假值(undefined、null 或 '') */ token?: string; + /** 密码提示 */ passwordHint?: string; + /** 附加的文本消息 */ message?: string; }; /** * 验证用户是否存在提交的参数 - * @param username 用户名 */ export type UserExistsCheckDataDto = { + /** 用户名 */ username: string; }; /** * 验证用户是否已经存在的返回参数 - * @param success 执行结果,程序执行成功,返回 true,程序执行失败,返回 false - * @param exists 用户存在或者查询失败(悲观)都会返回 true,不存在返回 false // WARN 注意:用户存在或查询失败时都会返回 true - * @param message 附加的文本消息 */ export type UserExistsCheckResultDto = { + /** 执行结果,程序执行成功,返回 true,程序执行失败,返回 false */ success: boolean; - exists: boolean; + /** 用户存在或者查询失败(悲观)都会返回 true,不存在返回 false */ + exists: boolean; // WARN 注意:用户存在或查询失败时都会返回 true + /** 附加的文本消息 */ message?: string; }; diff --git a/composables/api/Video/VideoController.ts b/composables/api/Video/VideoController.ts index 0958ae56..0e5b94cb 100644 --- a/composables/api/Video/VideoController.ts +++ b/composables/api/Video/VideoController.ts @@ -1,5 +1,5 @@ -import { getCorrectUri } from "../Common/GetCorrectUri"; -import { GetVideoByKvidResponseDto, ThumbVideoResponseDto, getVideoByKvidRequestDto } from "./VideoControllerDto"; +import getCorrectUri from "api/Common/getCorrectUri"; +import type { GetVideoByKvidResponseDto, ThumbVideoResponseDto, GetVideoByKvidRequestDto } from "./VideoControllerDto"; const BACK_END_URL = getCorrectUri(); const VIDEO_API_URI = `${BACK_END_URL}/video`; @@ -12,7 +12,7 @@ export const getHomePageThumbVideo = async (): Promise => return { success: false, videosCount: 0, videos: [], message: "获取首页视频失败" }; }; -export const getVideoByKvid = async (getVideoByKvidRequest: getVideoByKvidRequestDto): Promise => { +export const getVideoByKvid = async (getVideoByKvidRequest: GetVideoByKvidRequestDto): Promise => { if (getVideoByKvidRequest && getVideoByKvidRequest.videoId) { const { data: result } = await useFetch(`${VIDEO_API_URI}?videoId=${getVideoByKvidRequest.videoId}`); if (result.value) diff --git a/composables/api/Video/VideoControllerDto.d.ts b/composables/api/Video/VideoControllerDto.d.ts index cd1ad7e8..e907b855 100644 --- a/composables/api/Video/VideoControllerDto.d.ts +++ b/composables/api/Video/VideoControllerDto.d.ts @@ -1,43 +1,43 @@ /** - * @param id 分P ID - * @param 视频 分P 标题 - * @param 视频直链 + * 单个视频分 P 数据参数 */ -type videoPartDto = { +type VideoPartDto = { + /** 分 P ID */ id: number; + /** 视频分 P 标题 */ videoPartTitle: string; + /** 视频直链 */ link: string; }; /** * 展示视频卡片返回的参数 - * @param videoPart 每 P 视频的数据 - * @param videoPartDto[] 每 P 视频的数据 - * @param title 视频标题 - * @param image 封面图链接 - * @param uploader 视频作者 ID - * @param uploaderId 创作者 UID - * @param duration 视频时长,单位 ms - * @param description 视频描述 */ export type UploadVideoRequestDto = { - videoPart: videoPartDto[]; + /** 每 P 视频的数据 */ + videoPart: VideoPartDto[]; + /** 视频标题 */ title: string; + /** 封面图链接 */ image: string; + /** 视频作者 ID */ uploader: string; + /** 创作者 UID */ uploaderId: number; + /** 视频时长,单位 ms */ duration: number; + /** 视频描述 */ description?: string; }; /** * 视频上传的返回的参数 - * @param success 是否请求成功 - * @param message 附加的文本消息 - * @parma videoId 视频 ID */ export type UploadVideoResponseDto = { + /** 是否请求成功 */ success: boolean; + /** 附加的文本消息 */ message?: string; + /** 视频 ID */ videoId?: number; }; @@ -47,75 +47,76 @@ export type UploadVideoResponseDto = { /** * 展示视频卡片需要的返回参数 - * @param success 是否请求成功 - * @param message 附加的文本消息 - * @param videosCount 获取到的视频数量,如果没获取到则为 0 - * @param videos 请求到的视频的数据 - * @param videoId KVID 视频 ID - * @param title 视频标题 - * @param image 封面图链接 - * @param updateDate 频上传的日期,时间戳格式 - * @param watchedCount 视频播放量 - * @param uploader 视频作者 ID - * @param uploaderId 创作者 UID - * @param duration 视频时长,单位 ms - * @param description 视频描述 */ export type ThumbVideoResponseDto = { + /** 是否请求成功 */ success: boolean; + /** 附加的文本消息 */ message?: string; + /** 获取到的视频数量,如果没获取到则为 0 */ videosCount: number; + /** 请求到的视频的数据 */ videos: { + /** 视频 ID (KVID) */ videoId: number; + /** 视频标题 */ title: string; + /** 封面图链接 */ image?: string; + /** 视频上传的日期,时间戳格式 */ updateDate?: number; + /** 视频播放量 */ watchedCount?: number; + /** 视频作者 ID */ uploader?: string; + /** 创作者 UID */ uploaderId?: number; + /** 视频时长,单位 ms */ duration?: number; + /** 视频描述 */ description?: string; }[]; }; /** - * @param videoId kvid 视频的自增 ID + * 从视频 ID 获取视频的请求 */ -export type getVideoByKvidRequestDto = { +export type GetVideoByKvidRequestDto = { + /** kvid 视频的自增 ID */ videoId: number; }; /** * 视频页面需要的响应 - * @param success 是否请求成功 - * @param message 附加的文本消息 - * @param videosCount 获取到的视频数量,如果没获取到则为 0 - * @param video 请求到的视频的数据 - * @param videoId KVID 视频 ID - * @param videoPart 视频 分P 数据 - * @param videoPartDto[] 视频 分P 数据 - * @param title 视频标题 - * @param image 封面图链接 - * @param updateDate 频上传的日期,时间戳格式 - * @param watchedCount 视频播放量 - * @param uploader 视频作者 ID - * @param uploaderId 创作者 UID - * @param duration 视频时长,单位 ms - * @param description 视频描述 */ export type GetVideoByKvidResponseDto = { + /** 是否请求成功 */ success: boolean; + /** 附加的文本消息 */ message?: string; + /** 获取到的视频数量,如果没获取到则为 0 */ + // videosCount: number; + /** 请求到的视频的数据 */ video?: { + /** 视频 ID (KVID) */ videoId: number; - videoPart: videoPartDto[]; + /** 视频分 P 数据 */ + videoPart: VideoPartDto[]; + /** 视频标题 */ title: string; + /** 封面图链接 */ image?: string; + /** 视频上传的日期,时间戳格式 */ updateDate?: number; + /** 视频播放量 */ watchedCount?: number; + /** 视频作者 ID */ uploader?: string; + /** 创作者 UID */ uploaderId?: number; + /** 视频时长,单位 ms */ duration?: number; + /** 视频描述 */ description?: string; }; }; diff --git a/nuxt.config.ts b/nuxt.config.ts index afd8cbcc..649d53f2 100755 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -64,6 +64,7 @@ export default defineNuxtConfig({ "utils", "worklets", "assets/pomsky", + "composables/api", ), css: [ "styles/global.scss", diff --git a/pages/video/kv[kvid].vue b/pages/video/kv[kvid].vue index b78794ac..05a1db1a 100644 --- a/pages/video/kv[kvid].vue +++ b/pages/video/kv[kvid].vue @@ -1,7 +1,7 @@