fix: types in the unified response
This commit is contained in:
parent
19393d7765
commit
66a89cdad2
@ -1,2 +1,2 @@
|
||||
export * from "./utils/switch"
|
||||
export * from "./utils/tiktok_stalker"
|
||||
export * from "./utils/downloader/tiktok_downloader"
|
||||
export * from "./utils/stalker/tiktok_stalker"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import Axios from "axios"
|
||||
import { load } from "cheerio"
|
||||
import { MusicalDownResponse, getMusic, getRequest } from "../types/musicaldown"
|
||||
import { _musicaldownapi, _musicaldownmusicapi, _musicaldownurl } from "../api"
|
||||
import { MusicalDownResponse, getMusic, getRequest } from "../../types/musicaldown"
|
||||
import { _musicaldownapi, _musicaldownmusicapi, _musicaldownurl } from "../../api"
|
||||
|
||||
/**
|
||||
* Using API from Website:
|
||||
@ -1,7 +1,7 @@
|
||||
import Axios from "axios"
|
||||
import { load } from "cheerio"
|
||||
import { Author, Statistics, SSSTikFetchTT, SSSTikResponse } from "../types/ssstik"
|
||||
import { _ssstikapi, _ssstikurl } from "../api"
|
||||
import { Author, Statistics, SSSTikFetchTT, SSSTikResponse } from "../../types/ssstik"
|
||||
import { _ssstikapi, _ssstikurl } from "../../api"
|
||||
|
||||
/**
|
||||
* Using API from Website:
|
||||
@ -16,7 +16,7 @@ const fetchTT = () =>
|
||||
}
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const regex = /form\.setAttribute\("include-vals",\s*"([^"]+)"\)/
|
||||
const regex = /s_tt\s*=\s*["']([^"']+)["']/
|
||||
const match = data.match(regex)
|
||||
if (match) {
|
||||
const value = match[1]
|
||||
@ -1,6 +1,6 @@
|
||||
import axios from "axios"
|
||||
import { _tiktokapi, _tiktokurl } from "../api"
|
||||
import { Author, TiktokAPIResponse, Statistics, Music } from "../types/tiktokApi"
|
||||
import { _tiktokapi, _tiktokurl } from "../../api"
|
||||
import { Author, TiktokAPIResponse, Statistics, Music } from "../../types/tiktokApi"
|
||||
|
||||
export const TiktokAPI = (url: string) =>
|
||||
new Promise<TiktokAPIResponse>((resolve, reject) => {
|
||||
31
src/utils/downloader/tiktok_downloader.ts
Normal file
31
src/utils/downloader/tiktok_downloader.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { MusicalDown } from "./downloader_musicaldown"
|
||||
import { SSSTik } from "./downloader_ssstik"
|
||||
import { TiktokAPI } from "./downloader_tiktokApi"
|
||||
|
||||
/** Types */
|
||||
import { MusicalDownResponse } from "../../types/musicaldown"
|
||||
import { SSSTikResponse } from "../../types/ssstik"
|
||||
import { TiktokAPIResponse } from "../../types/tiktokApi"
|
||||
|
||||
type TiktokDownloaderResponse<T extends "v1" | "v2" | "v3"> = T extends "v1" ? TiktokAPIResponse : T extends "v2" ? SSSTikResponse : T extends "v3" ? MusicalDownResponse : TiktokAPIResponse
|
||||
|
||||
export const TiktokDownloader = async <T extends "v1" | "v2" | "v3">(url: string, options?: { version: T }): Promise<TiktokDownloaderResponse<T>> => {
|
||||
switch (options?.version) {
|
||||
case "v1": {
|
||||
const response = await TiktokAPI(url)
|
||||
return response as TiktokDownloaderResponse<T>
|
||||
}
|
||||
case "v2": {
|
||||
const response = await SSSTik(url)
|
||||
return response as TiktokDownloaderResponse<T>
|
||||
}
|
||||
case "v3": {
|
||||
const response = await MusicalDown(url)
|
||||
return response as TiktokDownloaderResponse<T>
|
||||
}
|
||||
default: {
|
||||
const response = await TiktokAPI(url)
|
||||
return response as TiktokDownloaderResponse<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import axios from "axios"
|
||||
import { load } from "cheerio"
|
||||
import { _tiktokurl } from "../api"
|
||||
import { StalkResult, Stats, Users } from "../types/stalker"
|
||||
import { _tiktokurl } from "../../api"
|
||||
import { StalkResult, Stats, Users } from "../../types/stalker"
|
||||
|
||||
const getCookie = () =>
|
||||
new Promise((resolve, reject) => {
|
||||
@ -13,7 +13,7 @@ const getCookie = () =>
|
||||
.catch((e) => resolve({ status: "error", message: "Failed to fetch cookie." }))
|
||||
})
|
||||
|
||||
export const TiktokStalk = (username: string, options: { cookie: string }): Promise<StalkResult> =>
|
||||
export const TiktokStalk = (username: string, options?: { cookie: string }): Promise<StalkResult> =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
username = username.replace("@", "")
|
||||
axios
|
||||
@ -1,34 +0,0 @@
|
||||
import { MusicalDown } from "./downloader_musicaldown"
|
||||
import { SSSTik } from "./downloader_ssstik"
|
||||
import { TiktokAPI } from "./downloader_tiktokApi"
|
||||
|
||||
/** Types */
|
||||
import { MusicalDownResponse } from "../types/musicaldown"
|
||||
import { SSSTikResponse } from "../types/ssstik"
|
||||
import { TiktokAPIResponse } from "../types/tiktokApi"
|
||||
|
||||
export const TiktokDL = (url: string, options: { version: "v1" | "v2" | "v3" }): Promise<TiktokAPIResponse | SSSTikResponse | MusicalDownResponse> =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
switch (options.version) {
|
||||
case "v1": {
|
||||
const response: TiktokAPIResponse = await TiktokAPI(url)
|
||||
resolve(response)
|
||||
break
|
||||
}
|
||||
case "v2": {
|
||||
const response: SSSTikResponse = await SSSTik(url)
|
||||
resolve(response)
|
||||
break
|
||||
}
|
||||
case "v3": {
|
||||
const response: MusicalDownResponse = await MusicalDown(url)
|
||||
resolve(response)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
const response: TiktokAPIResponse = await TiktokAPI(url)
|
||||
resolve(response)
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user