style: 统一代码格式和行尾
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
import { postForm, postJson } from './client'
|
||||
import type { Account, MessageResponse, TokenResponse } from './types'
|
||||
|
||||
export function register(username: string, password: string) {
|
||||
return postJson<MessageResponse>('/account/register', { username, password })
|
||||
}
|
||||
|
||||
export function login(username: string, password: string) {
|
||||
return postJson<TokenResponse>('/account/login', { username, password })
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return postJson<MessageResponse>('/account/logout', {}, { authRequired: true })
|
||||
}
|
||||
|
||||
export function rename(newUsername: string) {
|
||||
return postJson<TokenResponse>('/account/rename', { new_username: newUsername }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function changePassword(username: string, oldPassword: string, newPassword: string) {
|
||||
return postJson<MessageResponse>('/account/changePassword', {
|
||||
username,
|
||||
old_password: oldPassword,
|
||||
new_password: newPassword,
|
||||
})
|
||||
}
|
||||
|
||||
export function findById(id: number) {
|
||||
return postJson<Account>('/account/findByID', { id })
|
||||
}
|
||||
|
||||
export function findByUsername(username: string) {
|
||||
return postJson<Account>('/account/findByUsername', { username })
|
||||
}
|
||||
|
||||
export function uploadAvatar(file: File) {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
return postForm<{ avatar_url: string }>('/account/uploadAvatar', fd, { authRequired: true })
|
||||
}
|
||||
|
||||
export function updateProfile(data: { avatar_url?: string; bio?: string }) {
|
||||
return postJson<MessageResponse>('/account/updateProfile', data, { authRequired: true })
|
||||
}
|
||||
|
||||
export function refresh(refreshToken: string) {
|
||||
return postJson<TokenResponse>('/account/refresh', { refresh_token: refreshToken })
|
||||
}
|
||||
import { postForm, postJson } from './client'
|
||||
import type { Account, MessageResponse, TokenResponse } from './types'
|
||||
|
||||
export function register(username: string, password: string) {
|
||||
return postJson<MessageResponse>('/account/register', { username, password })
|
||||
}
|
||||
|
||||
export function login(username: string, password: string) {
|
||||
return postJson<TokenResponse>('/account/login', { username, password })
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return postJson<MessageResponse>('/account/logout', {}, { authRequired: true })
|
||||
}
|
||||
|
||||
export function rename(newUsername: string) {
|
||||
return postJson<TokenResponse>('/account/rename', { new_username: newUsername }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function changePassword(username: string, oldPassword: string, newPassword: string) {
|
||||
return postJson<MessageResponse>('/account/changePassword', {
|
||||
username,
|
||||
old_password: oldPassword,
|
||||
new_password: newPassword,
|
||||
})
|
||||
}
|
||||
|
||||
export function findById(id: number) {
|
||||
return postJson<Account>('/account/findByID', { id })
|
||||
}
|
||||
|
||||
export function findByUsername(username: string) {
|
||||
return postJson<Account>('/account/findByUsername', { username })
|
||||
}
|
||||
|
||||
export function uploadAvatar(file: File) {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
return postForm<{ avatar_url: string }>('/account/uploadAvatar', fd, { authRequired: true })
|
||||
}
|
||||
|
||||
export function updateProfile(data: { avatar_url?: string; bio?: string }) {
|
||||
return postJson<MessageResponse>('/account/updateProfile', data, { authRequired: true })
|
||||
}
|
||||
|
||||
export function refresh(refreshToken: string) {
|
||||
return postJson<TokenResponse>('/account/refresh', { refresh_token: refreshToken })
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { postJson } from './client'
|
||||
import { normalizeCommentList } from './normalize'
|
||||
import type { Comment, MessageResponse } from './types'
|
||||
|
||||
export async function listAll(videoId: number) {
|
||||
const comments = await postJson<Comment[] | null>('/comment/listAll', { video_id: videoId })
|
||||
return normalizeCommentList(comments)
|
||||
}
|
||||
|
||||
export function publish(videoId: number, content: string) {
|
||||
return postJson<MessageResponse>('/comment/publish', { video_id: videoId, content }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function remove(commentId: number) {
|
||||
return postJson<MessageResponse>('/comment/delete', { comment_id: commentId }, { authRequired: true })
|
||||
}
|
||||
import { postJson } from './client'
|
||||
import { normalizeCommentList } from './normalize'
|
||||
import type { Comment, MessageResponse } from './types'
|
||||
|
||||
export async function listAll(videoId: number) {
|
||||
const comments = await postJson<Comment[] | null>('/comment/listAll', { video_id: videoId })
|
||||
return normalizeCommentList(comments)
|
||||
}
|
||||
|
||||
export function publish(videoId: number, content: string) {
|
||||
return postJson<MessageResponse>('/comment/publish', { video_id: videoId, content }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function remove(commentId: number) {
|
||||
return postJson<MessageResponse>('/comment/delete', { comment_id: commentId }, { authRequired: true })
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { postJson } from './client'
|
||||
import { normalizeFeedVideoList } from './normalize'
|
||||
import type { ListByFollowingResponse, ListByPopularityResponse, ListLatestResponse, ListLikesCountResponse } from './types'
|
||||
|
||||
export async function listLatest(input: { limit: number; latest_time: number }) {
|
||||
const res = await postJson<ListLatestResponse>('/feed/listLatest', input)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listLikesCount(input: { limit: number; likes_count_before?: number; id_before?: number }) {
|
||||
const body: Record<string, unknown> = { limit: input.limit }
|
||||
if (typeof input.likes_count_before === 'number' || typeof input.id_before === 'number') {
|
||||
body.likes_count_before = input.likes_count_before ?? 0
|
||||
body.id_before = input.id_before ?? 0
|
||||
}
|
||||
const res = await postJson<ListLikesCountResponse>('/feed/listLikesCount', body)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listByPopularity(input: { limit: number; as_of: number; offset: number }) {
|
||||
const res = await postJson<ListByPopularityResponse>('/feed/listByPopularity', input)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listByFollowing(input: { limit: number; latest_time: number }) {
|
||||
const res = await postJson<ListByFollowingResponse>('/feed/listByFollowing', input, { authRequired: true })
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
import { postJson } from './client'
|
||||
import { normalizeFeedVideoList } from './normalize'
|
||||
import type { ListByFollowingResponse, ListByPopularityResponse, ListLatestResponse, ListLikesCountResponse } from './types'
|
||||
|
||||
export async function listLatest(input: { limit: number; latest_time: number }) {
|
||||
const res = await postJson<ListLatestResponse>('/feed/listLatest', input)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listLikesCount(input: { limit: number; likes_count_before?: number; id_before?: number }) {
|
||||
const body: Record<string, unknown> = { limit: input.limit }
|
||||
if (typeof input.likes_count_before === 'number' || typeof input.id_before === 'number') {
|
||||
body.likes_count_before = input.likes_count_before ?? 0
|
||||
body.id_before = input.id_before ?? 0
|
||||
}
|
||||
const res = await postJson<ListLikesCountResponse>('/feed/listLikesCount', body)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listByPopularity(input: { limit: number; as_of: number; offset: number }) {
|
||||
const res = await postJson<ListByPopularityResponse>('/feed/listByPopularity', input)
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
export async function listByFollowing(input: { limit: number; latest_time: number }) {
|
||||
const res = await postJson<ListByFollowingResponse>('/feed/listByFollowing', input, { authRequired: true })
|
||||
return { ...res, video_list: normalizeFeedVideoList(res.video_list) }
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { postJson } from './client'
|
||||
import type { IsLikedResponse, MessageResponse, Video } from './types'
|
||||
|
||||
export function like(videoId: number) {
|
||||
return postJson<MessageResponse>('/like/like', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function unlike(videoId: number) {
|
||||
return postJson<MessageResponse>('/like/unlike', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function isLiked(videoId: number) {
|
||||
return postJson<IsLikedResponse>('/like/isLiked', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function listMyLikedVideos() {
|
||||
return postJson<Video[]>('/like/listMyLikedVideos', {}, { authRequired: true })
|
||||
}
|
||||
import { postJson } from './client'
|
||||
import type { IsLikedResponse, MessageResponse, Video } from './types'
|
||||
|
||||
export function like(videoId: number) {
|
||||
return postJson<MessageResponse>('/like/like', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function unlike(videoId: number) {
|
||||
return postJson<MessageResponse>('/like/unlike', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function isLiked(videoId: number) {
|
||||
return postJson<IsLikedResponse>('/like/isLiked', { video_id: videoId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function listMyLikedVideos() {
|
||||
return postJson<Video[]>('/like/listMyLikedVideos', {}, { authRequired: true })
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
import type { Account, Comment, FeedAuthor, FeedVideoItem, Video } from './types'
|
||||
|
||||
export function listOrEmpty<T>(value: T[] | null | undefined): T[] {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
export function normalizeAccount(value: Account | null | undefined): Account {
|
||||
return {
|
||||
id: Number(value?.id ?? 0),
|
||||
username: value?.username || '匿名用户',
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAuthor(value: FeedAuthor | null | undefined): FeedAuthor {
|
||||
return {
|
||||
id: Number(value?.id ?? 0),
|
||||
username: value?.username || '匿名用户',
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFeedVideoItem(value: FeedVideoItem): FeedVideoItem {
|
||||
return {
|
||||
...value,
|
||||
author: normalizeAuthor(value.author),
|
||||
title: value.title || '未命名视频',
|
||||
description: value.description || '',
|
||||
play_url: value.play_url || '',
|
||||
cover_url: value.cover_url || '',
|
||||
create_time: Number(value.create_time ?? 0),
|
||||
likes_count: Number(value.likes_count ?? 0),
|
||||
is_liked: Boolean(value.is_liked),
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFeedVideoList(value: FeedVideoItem[] | null | undefined): FeedVideoItem[] {
|
||||
return listOrEmpty(value).map(normalizeFeedVideoItem)
|
||||
}
|
||||
|
||||
export function normalizeVideoList(value: Video[] | null | undefined): Video[] {
|
||||
return listOrEmpty(value).map((video) => ({
|
||||
...video,
|
||||
username: video.username || '匿名用户',
|
||||
title: video.title || '未命名视频',
|
||||
description: video.description || '',
|
||||
play_url: video.play_url || '',
|
||||
cover_url: video.cover_url || '',
|
||||
likes_count: Number(video.likes_count ?? 0),
|
||||
}))
|
||||
}
|
||||
|
||||
export function normalizeCommentList(value: Comment[] | null | undefined): Comment[] {
|
||||
return listOrEmpty(value).map((comment) => ({
|
||||
...comment,
|
||||
username: comment.username || '匿名用户',
|
||||
content: comment.content || '',
|
||||
}))
|
||||
}
|
||||
import type { Account, Comment, FeedAuthor, FeedVideoItem, Video } from './types'
|
||||
|
||||
export function listOrEmpty<T>(value: T[] | null | undefined): T[] {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
export function normalizeAccount(value: Account | null | undefined): Account {
|
||||
return {
|
||||
id: Number(value?.id ?? 0),
|
||||
username: value?.username || '匿名用户',
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAuthor(value: FeedAuthor | null | undefined): FeedAuthor {
|
||||
return {
|
||||
id: Number(value?.id ?? 0),
|
||||
username: value?.username || '匿名用户',
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFeedVideoItem(value: FeedVideoItem): FeedVideoItem {
|
||||
return {
|
||||
...value,
|
||||
author: normalizeAuthor(value.author),
|
||||
title: value.title || '未命名视频',
|
||||
description: value.description || '',
|
||||
play_url: value.play_url || '',
|
||||
cover_url: value.cover_url || '',
|
||||
create_time: Number(value.create_time ?? 0),
|
||||
likes_count: Number(value.likes_count ?? 0),
|
||||
is_liked: Boolean(value.is_liked),
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFeedVideoList(value: FeedVideoItem[] | null | undefined): FeedVideoItem[] {
|
||||
return listOrEmpty(value).map(normalizeFeedVideoItem)
|
||||
}
|
||||
|
||||
export function normalizeVideoList(value: Video[] | null | undefined): Video[] {
|
||||
return listOrEmpty(value).map((video) => ({
|
||||
...video,
|
||||
username: video.username || '匿名用户',
|
||||
title: video.title || '未命名视频',
|
||||
description: video.description || '',
|
||||
play_url: video.play_url || '',
|
||||
cover_url: video.cover_url || '',
|
||||
likes_count: Number(video.likes_count ?? 0),
|
||||
}))
|
||||
}
|
||||
|
||||
export function normalizeCommentList(value: Comment[] | null | undefined): Comment[] {
|
||||
return listOrEmpty(value).map((comment) => ({
|
||||
...comment,
|
||||
username: comment.username || '匿名用户',
|
||||
content: comment.content || '',
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { postJson } from './client'
|
||||
import { listOrEmpty, normalizeAccount } from './normalize'
|
||||
import type { GetAllFollowersResponse, GetAllVloggersResponse, MessageResponse } from './types'
|
||||
|
||||
export function follow(vloggerId: number) {
|
||||
return postJson<MessageResponse>('/social/follow', { vlogger_id: vloggerId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function unfollow(vloggerId: number) {
|
||||
return postJson<MessageResponse>('/social/unfollow', { vlogger_id: vloggerId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export async function getAllFollowers(vloggerId?: number) {
|
||||
const res = await postJson<GetAllFollowersResponse>(
|
||||
'/social/getAllFollowers',
|
||||
vloggerId ? { vlogger_id: vloggerId } : {},
|
||||
{ authRequired: true },
|
||||
)
|
||||
return { ...res, followers: listOrEmpty(res.followers).map(normalizeAccount) }
|
||||
}
|
||||
|
||||
export async function getAllVloggers(followerId?: number) {
|
||||
const res = await postJson<GetAllVloggersResponse>(
|
||||
'/social/getAllVloggers',
|
||||
followerId ? { follower_id: followerId } : {},
|
||||
{ authRequired: true },
|
||||
)
|
||||
return { ...res, vloggers: listOrEmpty(res.vloggers).map(normalizeAccount) }
|
||||
}
|
||||
import { postJson } from './client'
|
||||
import { listOrEmpty, normalizeAccount } from './normalize'
|
||||
import type { GetAllFollowersResponse, GetAllVloggersResponse, MessageResponse } from './types'
|
||||
|
||||
export function follow(vloggerId: number) {
|
||||
return postJson<MessageResponse>('/social/follow', { vlogger_id: vloggerId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export function unfollow(vloggerId: number) {
|
||||
return postJson<MessageResponse>('/social/unfollow', { vlogger_id: vloggerId }, { authRequired: true })
|
||||
}
|
||||
|
||||
export async function getAllFollowers(vloggerId?: number) {
|
||||
const res = await postJson<GetAllFollowersResponse>(
|
||||
'/social/getAllFollowers',
|
||||
vloggerId ? { vlogger_id: vloggerId } : {},
|
||||
{ authRequired: true },
|
||||
)
|
||||
return { ...res, followers: listOrEmpty(res.followers).map(normalizeAccount) }
|
||||
}
|
||||
|
||||
export async function getAllVloggers(followerId?: number) {
|
||||
const res = await postJson<GetAllVloggersResponse>(
|
||||
'/social/getAllVloggers',
|
||||
followerId ? { follower_id: followerId } : {},
|
||||
{ authRequired: true },
|
||||
)
|
||||
return { ...res, vloggers: listOrEmpty(res.vloggers).map(normalizeAccount) }
|
||||
}
|
||||
|
||||
@@ -14,89 +14,89 @@ export type ListMessagesResponse = {
|
||||
}
|
||||
|
||||
export type TokenResponse = { token: string; refresh_token?: string; account_id?: number; username?: string }
|
||||
|
||||
export type Account = {
|
||||
id: number
|
||||
username: string
|
||||
avatar_url?: string
|
||||
bio?: string
|
||||
}
|
||||
|
||||
export type Video = {
|
||||
id: number
|
||||
author_id: number
|
||||
username: string
|
||||
title: string
|
||||
description?: string
|
||||
play_url: string
|
||||
cover_url: string
|
||||
create_time: string
|
||||
likes_count: number
|
||||
}
|
||||
|
||||
export type Comment = {
|
||||
id: number
|
||||
username: string
|
||||
video_id: number
|
||||
author_id: number
|
||||
content: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type FeedAuthor = {
|
||||
id: number
|
||||
username: string
|
||||
}
|
||||
|
||||
export type FeedVideoItem = {
|
||||
id: number
|
||||
author: FeedAuthor
|
||||
title: string
|
||||
description?: string
|
||||
play_url: string
|
||||
cover_url: string
|
||||
create_time: number
|
||||
likes_count: number
|
||||
is_liked: boolean
|
||||
}
|
||||
|
||||
export type ListLatestResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_time: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type ListLikesCountResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_likes_count_before?: number
|
||||
next_id_before?: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type ListByPopularityResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
as_of: number
|
||||
next_offset: number
|
||||
has_more: boolean
|
||||
next_latest_popularity?: number
|
||||
next_latest_before?: string
|
||||
next_latest_id_before?: number
|
||||
}
|
||||
|
||||
export type ListByFollowingResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_time: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type IsLikedResponse = {
|
||||
is_liked: boolean
|
||||
}
|
||||
|
||||
export type GetAllFollowersResponse = {
|
||||
followers: Account[]
|
||||
}
|
||||
|
||||
export type GetAllVloggersResponse = {
|
||||
vloggers: Account[]
|
||||
}
|
||||
|
||||
export type Account = {
|
||||
id: number
|
||||
username: string
|
||||
avatar_url?: string
|
||||
bio?: string
|
||||
}
|
||||
|
||||
export type Video = {
|
||||
id: number
|
||||
author_id: number
|
||||
username: string
|
||||
title: string
|
||||
description?: string
|
||||
play_url: string
|
||||
cover_url: string
|
||||
create_time: string
|
||||
likes_count: number
|
||||
}
|
||||
|
||||
export type Comment = {
|
||||
id: number
|
||||
username: string
|
||||
video_id: number
|
||||
author_id: number
|
||||
content: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type FeedAuthor = {
|
||||
id: number
|
||||
username: string
|
||||
}
|
||||
|
||||
export type FeedVideoItem = {
|
||||
id: number
|
||||
author: FeedAuthor
|
||||
title: string
|
||||
description?: string
|
||||
play_url: string
|
||||
cover_url: string
|
||||
create_time: number
|
||||
likes_count: number
|
||||
is_liked: boolean
|
||||
}
|
||||
|
||||
export type ListLatestResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_time: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type ListLikesCountResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_likes_count_before?: number
|
||||
next_id_before?: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type ListByPopularityResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
as_of: number
|
||||
next_offset: number
|
||||
has_more: boolean
|
||||
next_latest_popularity?: number
|
||||
next_latest_before?: string
|
||||
next_latest_id_before?: number
|
||||
}
|
||||
|
||||
export type ListByFollowingResponse = {
|
||||
video_list: FeedVideoItem[]
|
||||
next_time: number
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
export type IsLikedResponse = {
|
||||
is_liked: boolean
|
||||
}
|
||||
|
||||
export type GetAllFollowersResponse = {
|
||||
followers: Account[]
|
||||
}
|
||||
|
||||
export type GetAllVloggersResponse = {
|
||||
vloggers: Account[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user