From 4dda8daf85149b110d3e965fe67b414099b040de Mon Sep 17 00:00:00 2001 From: Tobi Saputra Date: Tue, 13 May 2025 18:24:20 +0700 Subject: [PATCH] fix: fixing several types --- src/constants/index.ts | 26 +++++++++ src/types/common.ts | 74 +++++++++++++++++++++++++ src/types/downloader/musicaldown.ts | 26 ++------- src/types/downloader/ssstik.ts | 32 +++-------- src/types/downloader/tiktokApi.ts | 85 +++++++---------------------- src/types/get/getUserPosts.ts | 2 +- src/types/search/index.ts | 18 ++++++ src/types/search/videoSearch.ts | 2 +- 8 files changed, 152 insertions(+), 113 deletions(-) create mode 100644 src/constants/index.ts create mode 100644 src/types/common.ts create mode 100644 src/types/search/index.ts diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..be6254c --- /dev/null +++ b/src/constants/index.ts @@ -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 diff --git a/src/types/common.ts b/src/types/common.ts new file mode 100644 index 0000000..4f2bfdd --- /dev/null +++ b/src/types/common.ts @@ -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 +} diff --git a/src/types/downloader/musicaldown.ts b/src/types/downloader/musicaldown.ts index e4a4514..a7ab306 100644 --- a/src/types/downloader/musicaldown.ts +++ b/src/types/downloader/musicaldown.ts @@ -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 } diff --git a/src/types/downloader/ssstik.ts b/src/types/downloader/ssstik.ts index 0b8da34..7ed4413 100644 --- a/src/types/downloader/ssstik.ts +++ b/src/types/downloader/ssstik.ts @@ -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 diff --git a/src/types/downloader/tiktokApi.ts b/src/types/downloader/tiktokApi.ts index b48eaef..c3d6ff9 100644 --- a/src/types/downloader/tiktokApi.ts +++ b/src/types/downloader/tiktokApi.ts @@ -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 diff --git a/src/types/get/getUserPosts.ts b/src/types/get/getUserPosts.ts index fffc1fe..92f4ee2 100644 --- a/src/types/get/getUserPosts.ts +++ b/src/types/get/getUserPosts.ts @@ -27,7 +27,7 @@ export type Posts = { export type StatsPost = { collectCount: number commentCount: number - diggCount: number + likeCount: number playCount: number shareCount: number } diff --git a/src/types/search/index.ts b/src/types/search/index.ts new file mode 100644 index 0000000..e45da7e --- /dev/null +++ b/src/types/search/index.ts @@ -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 +} diff --git a/src/types/search/videoSearch.ts b/src/types/search/videoSearch.ts index 4caa3ae..15a1f0b 100644 --- a/src/types/search/videoSearch.ts +++ b/src/types/search/videoSearch.ts @@ -30,7 +30,7 @@ export type VideoSearch = { export type StatisticsVideoSearch = { collectCount: number commentCount: number - diggCount: number + likeCount: number playCount: number shareCount: number }