From 03a081d87b60b8431ce61aa076be87c5f33951d0 Mon Sep 17 00:00:00 2001 From: Tobi Saputra Date: Sat, 7 Dec 2024 23:51:38 +0700 Subject: [PATCH] feat: add turn off comment status for v1 --- src/types/downloader/tiktokApi.ts | 2 ++ src/utils/downloader/tiktokApi.ts | 39 ++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/types/downloader/tiktokApi.ts b/src/types/downloader/tiktokApi.ts index 9190e01..474d855 100644 --- a/src/types/downloader/tiktokApi.ts +++ b/src/types/downloader/tiktokApi.ts @@ -9,6 +9,7 @@ export type TiktokAPIResponse = { author: Author statistics: Statistics hashtag: string[] + isTurnOffComment: boolean isADS: boolean cover?: string[] dynamicCover?: string[] @@ -17,6 +18,7 @@ export type TiktokAPIResponse = { images?: string[] music: Music } + resultNotParsed?: any } export type Author = { diff --git a/src/utils/downloader/tiktokApi.ts b/src/utils/downloader/tiktokApi.ts index 59e9b36..8529e94 100644 --- a/src/utils/downloader/tiktokApi.ts +++ b/src/utils/downloader/tiktokApi.ts @@ -20,11 +20,16 @@ const TiktokURLregex = * Tiktok API Downloader * @param {string} url - Tiktok URL * @param {string} proxy - Your Proxy (optional) + * @param {boolean} showOriginalResponse - Show Original Response (optional) * @returns {Promise} */ -export const TiktokAPI = (url: string, proxy?: string) => - new Promise((resolve) => { +export const TiktokAPI = ( + url: string, + proxy?: string, + showOriginalResponse?: boolean +): Promise => + new Promise((resolve) => { if (!TiktokURLregex.test(url)) { return resolve({ status: "error", @@ -66,29 +71,31 @@ export const TiktokAPI = (url: string, proxy?: string) => const { content, author, statistics, music } = data2 + let response: TiktokAPIResponse // Download Result if (content.image_post_info) { // Images or Slide Result - resolve({ + response = { status: "success", result: { type: "image", id: content.aweme_id, createTime: content.create_time, description: content.desc, + isTurnOffComment: content.item_comment_settings === 3, hashtag: content.text_extra - .filter((x) => x.hashtag_name !== undefined) - .map((v) => v.hashtag_name), + .filter((x: any) => x.hashtag_name !== undefined) + .map((v: any) => v.hashtag_name), isADS: content.is_ads, author, statistics, images: content.image_post_info.images?.map( - (v) => v?.display_image?.url_list[0] + (v: any) => v?.display_image?.url_list[0] ) || [], music } - }) + } } else { // Video Result const video: Video = { @@ -101,24 +108,34 @@ export const TiktokAPI = (url: string, proxy?: string) => originCover: content.video?.origin_cover?.url_list || [] } - resolve({ + response = { status: "success", result: { type: "video", id: content.aweme_id, createTime: content.create_time, description: content.desc, + isTurnOffComment: content.item_comment_settings === 3, hashtag: content.text_extra - .filter((x) => x.hashtag_name !== undefined) - .map((v) => v.hashtag_name), + .filter((x: any) => x.hashtag_name !== undefined) + .map((v: any) => v.hashtag_name), isADS: content.is_ads, author, statistics, video, music } - }) + } } + + // Show Original Response + if (showOriginalResponse) { + response = { + status: "success", + resultNotParsed: data2 + } + } + resolve(response) }) .catch((e) => resolve({ status: "error", message: e.message })) })