fix: fixing several types

This commit is contained in:
Tobi Saputra 2025-05-13 18:24:20 +07:00
parent fb72a4f74a
commit 4dda8daf85
8 changed files with 152 additions and 113 deletions

26
src/constants/index.ts Normal file
View File

@ -0,0 +1,26 @@
export const DOWNLOADER_VERSIONS = {
V1: "v1",
V2: "v2",
V3: "v3"
} as const
export const SEARCH_TYPES = {
USER: "user",
LIVE: "live",
VIDEO: "video"
} as const
export const ERROR_MESSAGES = {
COOKIE_REQUIRED: "Cookie is required!",
INVALID_VERSION: "Invalid downloader version",
INVALID_SEARCH_TYPE: "Invalid search type",
INVALID_URL: "Invalid TikTok URL",
NETWORK_ERROR: "Network error occurred",
RATE_LIMIT: "Rate limit exceeded"
} as const
export const DEFAULT_LIMITS = {
POST_LIMIT: 30,
COMMENT_LIMIT: 20,
SEARCH_PAGE_SIZE: 20
} as const

74
src/types/common.ts Normal file
View File

@ -0,0 +1,74 @@
/** Common Types */
export type ResponseStatus = "success" | "error"
export type BaseResponse = {
status: ResponseStatus
message?: string
}
export type ContentType = "video" | "image" | "music"
export type Author = {
avatar?: string
nickname?: string
signature?: string
region?: string
url?: string
}
export type Statistics = {
likeCount?: string | number
commentCount?: string | number
shareCount?: string | number
playCount?: number
downloadCount?: number
}
export type Video = {
ratio?: string
duration?: number
playAddr?: string[]
downloadAddr?: string[]
cover?: string[]
dynamicCover?: string[]
originCover?: string[]
}
export type Music = {
id?: number
title?: string
author?: string
album?: string
playUrl?: string[]
coverLarge?: string[]
coverMedium?: string[]
coverThumb?: string[]
duration?: number
isCommerceMusic?: boolean
isOriginalSound?: boolean
isAuthorArtist?: boolean
}
export type Content = {
type: ContentType
id?: string
createTime?: number
desc?: string
author?: Author
statistics?: Statistics
hashtag?: string[]
isTurnOffComment?: boolean
isADS?: boolean
video?: Video
images?: string[]
music?: Music
videoHD?: string
videoSD?: string
videoWatermark?: string
direct?: string
}
export type BaseContentResponse = BaseResponse & {
result?: Content
resultNotParsed?: any
}

View File

@ -1,30 +1,16 @@
export type GetMusicalDownReuqest = {
status: "success" | "error"
import { BaseResponse, Content } from "../common"
export type GetMusicalDownReuqest = BaseResponse & {
request?: {
[key: string]: string
}
message?: string
cookie?: string
}
export type MusicalDownResponse = {
status: "success" | "error"
message?: string
result?: {
type: "video" | "image"
desc?: string
author?: {
avatar?: string
nickname?: string
}
music?: string
images?: string[]
videoHD?: string
videoWatermark?: string
}
export type MusicalDownResponse = BaseResponse & {
result?: Content
}
export type GetMusicalDownMusic = {
status: "success" | "error"
export type GetMusicalDownMusic = BaseResponse & {
result?: string
}

View File

@ -1,31 +1,13 @@
export type SSSTikFetchTT = {
status: "success" | "error"
message?: string
import { BaseResponse, Content, Author, Statistics } from "../common"
export type SSSTikFetchTT = BaseResponse & {
result?: string
}
export type SSSTikResponse = {
status: "success" | "error"
message?: string
result?: {
type: "image" | "video" | "music"
desc?: string
author?: AuthorSSSTik
statistics?: StatisticsSSSTik
images?: string[]
video?: string
music?: string
direct?: string
}
export type SSSTikResponse = BaseResponse & {
result?: Content
}
export type AuthorSSSTik = {
avatar: string
nickname: string
}
export type AuthorSSSTik = Author
export type StatisticsSSSTik = {
likeCount: string
commentCount: string
shareCount: string
}
export type StatisticsSSSTik = Statistics

View File

@ -1,75 +1,28 @@
export type TiktokAPIResponse = {
status: "success" | "error"
message?: string
result?: {
type: "video" | "image"
id: string
createTime: number
description: string
author: AuthorTiktokAPI
statistics: StatisticsTiktokAPI
hashtag: string[]
isTurnOffComment: boolean
isADS: boolean
cover?: string[]
dynamicCover?: string[]
originCover?: string[]
video?: VideoTiktokAPI
images?: string[]
music: MusicTiktokAPI
}
resultNotParsed?: any
}
import {
BaseContentResponse,
Content,
Author,
Statistics,
Video,
Music
} from "../common"
export type AuthorTiktokAPI = {
uid: number
export type TiktokAPIResponse = BaseContentResponse
export type AuthorTiktokAPI = Author & {
uid: string
username: string
nickname: string
signature: string
region: string
avatarThumb: string[]
avatarMedium: string[]
url: string
avatarThumb: string
avatarMedium: string
}
export type StatisticsTiktokAPI = {
playCount: number
downloadCount: number
shareCount: number
commentCount: number
diggCount: number
collectCount: number
forwardCount: number
whatsappShareCount: number
loseCount: number
loseCommentCount: number
repostCount: number
}
export type StatisticsTiktokAPI = Statistics
export type VideoTiktokAPI = {
ratio: string
duration: number
playAddr: string[]
downloadAddr: string[]
cover: string[]
dynamicCover: string[]
originCover: string[]
}
export type VideoTiktokAPI = Video
export type MusicTiktokAPI = {
id: number
title: string
author: string
album: string
playUrl: string[]
coverLarge: string[]
coverMedium: string[]
coverThumb: string[]
duration: number
isCommerceMusic: boolean
isOriginalSound: boolean
isAuthorArtist: boolean
}
export type MusicTiktokAPI = Music
export type ResultTiktokAPI = Content
export type ResponseParserTiktokAPI = {
content?: any

View File

@ -27,7 +27,7 @@ export type Posts = {
export type StatsPost = {
collectCount: number
commentCount: number
diggCount: number
likeCount: number
playCount: number
shareCount: number
}

18
src/types/search/index.ts Normal file
View File

@ -0,0 +1,18 @@
import { VideoSearchResult } from "./videoSearch"
import { LiveSearchResult } from "./liveSearch"
import { UserSearchResult } from "./userSearch"
export type SearchType = "video" | "live" | "user"
export type SearchResult = {
type: SearchType
data: VideoSearchResult | LiveSearchResult | UserSearchResult
}
export type TiktokSearchResponse = {
status: "success" | "error"
message?: string
result?: SearchResult[]
page?: number
totalResults?: number
}

View File

@ -30,7 +30,7 @@ export type VideoSearch = {
export type StatisticsVideoSearch = {
collectCount: number
commentCount: number
diggCount: number
likeCount: number
playCount: number
shareCount: number
}