refactor: changed the file name and API to ssstik

This commit is contained in:
TobyG74 2023-10-12 18:25:33 +07:00
parent 3697494696
commit 8bccf19644
3 changed files with 21 additions and 15 deletions

View File

@ -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?: {

View File

@ -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<TiktokFetchTT> =>
new Promise(async (resolve, reject) => {
Axios.get("https://tiktokdownload.online/", {
const fetchTT = () =>
new Promise<SSSTikFetchTT>(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<TiktokFetchTT> =>
.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<SSSTikResult>(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 }))
})

View File

@ -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)