From 8bccf19644aa42638e81a1340a112cbf0b07fdeb Mon Sep 17 00:00:00 2001 From: TobyG74 Date: Thu, 12 Oct 2023 18:25:33 +0700 Subject: [PATCH] refactor: changed the file name and API to ssstik --- src/types/{tiktokdownload.ts => ssstik.ts} | 4 ++-- src/utils/{tiktokdownload.ts => ssstik.ts} | 28 +++++++++++++--------- src/utils/switch.ts | 4 ++-- 3 files changed, 21 insertions(+), 15 deletions(-) rename src/types/{tiktokdownload.ts => ssstik.ts} (87%) rename src/utils/{tiktokdownload.ts => ssstik.ts} (71%) diff --git a/src/types/tiktokdownload.ts b/src/types/ssstik.ts similarity index 87% rename from src/types/tiktokdownload.ts rename to src/types/ssstik.ts index 9a75154..b3e8fb3 100644 --- a/src/types/tiktokdownload.ts +++ b/src/types/ssstik.ts @@ -1,10 +1,10 @@ -export interface TiktokFetchTT { +export interface SSSTikFetchTT { status: "success" | "error" message?: string result?: string } -export interface TiktokDownload { +export interface SSSTikResult { status: "success" | "error" message?: string result?: { diff --git a/src/utils/tiktokdownload.ts b/src/utils/ssstik.ts similarity index 71% rename from src/utils/tiktokdownload.ts rename to src/utils/ssstik.ts index f3a322b..18ca45a 100644 --- a/src/utils/tiktokdownload.ts +++ b/src/utils/ssstik.ts @@ -1,12 +1,12 @@ import Axios from "axios" import { load } from "cheerio" -import { Author, Statistics, TiktokFetchTT } from "../types/tiktokdownload" +import { Author, Statistics, SSSTikFetchTT, SSSTikResult } from "../types/ssstik" -const fetchTT = (): Promise => - new Promise(async (resolve, reject) => { - Axios.get("https://tiktokdownload.online/", { +const fetchTT = () => + new Promise(async (resolve, reject) => { + Axios.get("https://ssstik.io", { headers: { - "user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0" + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0" } }) .then(({ data }) => { @@ -22,12 +22,18 @@ const fetchTT = (): Promise => .catch((e) => resolve({ status: "error", message: e.message })) }) -export const TiktokDownload = (url: string) => - new Promise(async (resolve, reject) => { - const tt: TiktokFetchTT = await fetchTT() - if (tt.status !== "success") return resolve(tt) - Axios("https://tiktokdownload.online/abc?url=dl", { +export const SSSTik = (url: string) => + new Promise(async (resolve, reject) => { + const tt: SSSTikFetchTT = await fetchTT() + if (tt.status !== "success") return resolve({ status: "error", message: tt.message }) + Axios("https://ssstik.io/abc?url=dl", { method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + Origin: "https://ssstik.io", + Referer: "https://ssstik.io/en", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0" + }, data: new URLSearchParams( Object.entries({ id: url, @@ -87,5 +93,5 @@ export const TiktokDownload = (url: string) => }) } }) - .catch(console.log) + .catch((e) => resolve({ status: "error", message: e.message })) }) diff --git a/src/utils/switch.ts b/src/utils/switch.ts index 740f8e5..b90a798 100644 --- a/src/utils/switch.ts +++ b/src/utils/switch.ts @@ -1,4 +1,4 @@ -import { TiktokDownload } from "./tiktokdownload" +import { SSSTik } from "./ssstik" import { TiktokAPI } from "./tiktokapi" export const TiktokDL = (url: string, options: { version: "v1" | "v2" }) => @@ -8,7 +8,7 @@ export const TiktokDL = (url: string, options: { version: "v1" | "v2" }) => await TiktokAPI(url).then(resolve).catch(reject) } case "v2": { - await TiktokDownload(url).then(resolve).catch(reject) + await SSSTik(url).then(resolve).catch(reject) } default: { await TiktokAPI(url).then(resolve).catch(reject)