refactor: add type and move API to api folder
This commit is contained in:
parent
8bccf19644
commit
e649860c78
@ -1,2 +1,4 @@
|
|||||||
export const _tiktokurl: string = "https://www.tiktok.com"
|
export const _tiktokurl: string = "https://www.tiktok.com"
|
||||||
export const _tiktokapi = (id: string): string => `https://api.tiktokv.com/aweme/v1/feed/?aweme_id=${id}`
|
export const _tiktokapi = (id: string): string => `https://api.tiktokv.com/aweme/v1/feed/?aweme_id=${id}`
|
||||||
|
export const _ssstikapi: string = "https://ssstik.io/abc?url=dl"
|
||||||
|
export const _ssstikurl: string = "https://ssstik.io"
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import Axios from "axios"
|
import Axios from "axios"
|
||||||
import { load } from "cheerio"
|
import { load } from "cheerio"
|
||||||
import { Author, Statistics, SSSTikFetchTT, SSSTikResult } from "../types/ssstik"
|
import { Author, Statistics, SSSTikFetchTT, SSSTikResult } from "../types/ssstik"
|
||||||
|
import { _ssstikapi, _ssstikurl } from "../api"
|
||||||
|
|
||||||
const fetchTT = () =>
|
const fetchTT = () =>
|
||||||
new Promise<SSSTikFetchTT>(async (resolve, reject) => {
|
new Promise<SSSTikFetchTT>(async (resolve, reject) => {
|
||||||
Axios.get("https://ssstik.io", {
|
Axios.get(_ssstikurl, {
|
||||||
headers: {
|
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"
|
||||||
}
|
}
|
||||||
@ -26,19 +27,19 @@ export const SSSTik = (url: string) =>
|
|||||||
new Promise<SSSTikResult>(async (resolve, reject) => {
|
new Promise<SSSTikResult>(async (resolve, reject) => {
|
||||||
const tt: SSSTikFetchTT = await fetchTT()
|
const tt: SSSTikFetchTT = await fetchTT()
|
||||||
if (tt.status !== "success") return resolve({ status: "error", message: tt.message })
|
if (tt.status !== "success") return resolve({ status: "error", message: tt.message })
|
||||||
Axios("https://ssstik.io/abc?url=dl", {
|
Axios(_ssstikapi, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
Origin: "https://ssstik.io",
|
Origin: _ssstikurl,
|
||||||
Referer: "https://ssstik.io/en",
|
Referer: _ssstikurl + "/en",
|
||||||
"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"
|
||||||
},
|
},
|
||||||
data: new URLSearchParams(
|
data: new URLSearchParams(
|
||||||
Object.entries({
|
Object.entries({
|
||||||
id: url,
|
id: url,
|
||||||
locale: "en",
|
locale: "en",
|
||||||
tt: tt.result
|
tt: tt.result as string
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -48,7 +49,7 @@ export const SSSTik = (url: string) =>
|
|||||||
// Result
|
// Result
|
||||||
const desc = $("p.maintext").text().trim()
|
const desc = $("p.maintext").text().trim()
|
||||||
const author: Author = {
|
const author: Author = {
|
||||||
avatar: $("img.result_author").attr("src"),
|
avatar: $("img.result_author").attr("src") as string,
|
||||||
nickname: $("h2").text().trim()
|
nickname: $("h2").text().trim()
|
||||||
}
|
}
|
||||||
const statistics: Statistics = {
|
const statistics: Statistics = {
|
||||||
@ -62,7 +63,7 @@ export const SSSTik = (url: string) =>
|
|||||||
$("ul.splide__list > li")
|
$("ul.splide__list > li")
|
||||||
.get()
|
.get()
|
||||||
.map((img) => {
|
.map((img) => {
|
||||||
images.push($(img).find("img").attr("src"))
|
images.push($(img).find("img").attr("src") as string)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (images.length !== 0) {
|
if (images.length !== 0) {
|
||||||
@ -75,7 +76,7 @@ export const SSSTik = (url: string) =>
|
|||||||
author,
|
author,
|
||||||
statistics,
|
statistics,
|
||||||
images,
|
images,
|
||||||
music: $("a.music").attr("href")
|
music: $("a.music").attr("href") as string
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -88,7 +89,7 @@ export const SSSTik = (url: string) =>
|
|||||||
author,
|
author,
|
||||||
statistics,
|
statistics,
|
||||||
video: $("a.without_watermark").attr("href"),
|
video: $("a.without_watermark").attr("href"),
|
||||||
music: $("a.music").attr("href")
|
music: $("a.music").attr("href") as string
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user