From 978afeb713346e3e8db697d6bf189a6271507a12 Mon Sep 17 00:00:00 2001 From: TobyG74 Date: Wed, 6 Nov 2024 19:15:38 +0700 Subject: [PATCH] fix: SSSTik error when downloading Tiktok Story --- src/types/downloader/ssstik.ts | 2 +- src/utils/downloader/ssstik.ts | 49 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/types/downloader/ssstik.ts b/src/types/downloader/ssstik.ts index 1e46527..898ea56 100644 --- a/src/types/downloader/ssstik.ts +++ b/src/types/downloader/ssstik.ts @@ -14,7 +14,7 @@ export type SSSTikResponse = { statistics: Statistics images?: string[] video?: string - music: string + music?: string } } diff --git a/src/utils/downloader/ssstik.ts b/src/utils/downloader/ssstik.ts index a284720..3be8088 100644 --- a/src/utils/downloader/ssstik.ts +++ b/src/utils/downloader/ssstik.ts @@ -141,32 +141,35 @@ export const SSSTik = (url: string, proxy?: string) => images.push($(img).find("a").attr("href")) }) - if (images.length !== 0 && music) { + let result: SSSTikResponse["result"] + if (images.length !== 0) { // Images / Slide Result - resolve({ - status: "success", - result: { - type: "image", - author, - statistics, - images, - music - } - }) - } else if (video && music) { + result = { + type: "image", + desc: $("p.maintext").text().trim(), + author, + statistics, + images + } + + if (music) { + result.music = music + } + } else if (video) { // Video Result - resolve({ - status: "success", - result: { - type: "video", - desc: $("p.maintext").text().trim(), - author, - statistics, - video, - music - } - }) + result = { + type: "video", + desc: $("p.maintext").text().trim(), + author, + statistics, + video + } + + if (music) { + result.music = music + } } + resolve({ status: "success", result }) } catch (err) { resolve({ status: "error", message: err.message }) }