fix: downloader types

This commit is contained in:
TobyG74 2023-11-11 16:03:58 +07:00
parent fce7b8eab6
commit e42d40881e
2 changed files with 32 additions and 22 deletions

View File

@ -4,7 +4,7 @@ export interface StalkResult {
result?: { result?: {
users: Users users: Users
stats: Stats stats: Stats
posts: Posts[] // posts: Posts[]
} }
} }
@ -30,20 +30,20 @@ export interface Stats {
videoCount: number videoCount: number
likeCount: number likeCount: number
friendCount: number friendCount: number
postCount: number // postCount: number
} }
export interface Posts { // export interface Posts {
id: string // id: string
desc: string // desc: string
createTime: number // createTime: number
author: string // author: string
locationCreated: string // locationCreated: string
hashtags: string[] // hashtags: string[]
statistics: Statistics // statistics: Statistics
video: Video // video: Video
music: Music // music: Music
} // }
export interface Statistics { export interface Statistics {
likeCount: number likeCount: number

View File

@ -1,24 +1,34 @@
import { MusicalDownResponse } from "../types/musicaldown"
import { SSSTikResponse } from "../types/ssstik"
import { TiktokAPIResponse } from "../types/tiktokApi"
import { MusicalDown } from "./downloader_musicaldown" import { MusicalDown } from "./downloader_musicaldown"
import { SSSTik } from "./downloader_ssstik" import { SSSTik } from "./downloader_ssstik"
import { TiktokAPI } from "./downloader_tiktokApi" import { TiktokAPI } from "./downloader_tiktokApi"
export const TiktokDL = (url: string, options: { version: "v1" | "v2" | "v3" }) => /** Types */
new Promise<TiktokAPIResponse | SSSTikResponse | MusicalDownResponse>(async (resolve, reject) => { 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) { switch (options.version) {
case "v1": { case "v1": {
await TiktokAPI(url).then(resolve).catch(reject) const response: TiktokAPIResponse = await TiktokAPI(url)
resolve(response)
break
} }
case "v2": { case "v2": {
await SSSTik(url).then(resolve).catch(reject) const response: SSSTikResponse = await SSSTik(url)
resolve(response)
break
} }
case "v3": { case "v3": {
await MusicalDown(url).then(resolve).catch(reject) const response: MusicalDownResponse = await MusicalDown(url)
resolve(response)
break
} }
default: { default: {
await TiktokAPI(url).then(resolve).catch(reject) const response: TiktokAPIResponse = await TiktokAPI(url)
resolve(response)
break
} }
} }
}) })