feat: adding result validation
This commit is contained in:
parent
bd26a3b1b9
commit
79913008bf
@ -56,6 +56,13 @@ export const getComments = async (
|
||||
ID = ID[0]
|
||||
|
||||
const resultComments = await parseComments(ID, commentLimit, proxy)
|
||||
|
||||
if (!resultComments.comments.length)
|
||||
return resolve({
|
||||
status: "error",
|
||||
message: "No comments found!"
|
||||
})
|
||||
|
||||
return resolve({
|
||||
status: "success",
|
||||
result: resultComments.comments,
|
||||
|
||||
@ -43,6 +43,12 @@ export const getUserLiked = (
|
||||
const secUid = res.result.user.secUid
|
||||
const data = await parseUserLiked(id, secUid, cookie, postLimit, proxy)
|
||||
|
||||
if (!data.length)
|
||||
return resolve({
|
||||
status: "error",
|
||||
message: "User not found!"
|
||||
})
|
||||
|
||||
resolve({
|
||||
status: "success",
|
||||
result: data,
|
||||
@ -69,12 +75,6 @@ const parseUserLiked = async (
|
||||
// Prevent missing response favorites
|
||||
result = await requestUserLiked(id, secUid, cookie, postLimit, proxy)
|
||||
|
||||
// Validate
|
||||
if (result === "") {
|
||||
hasMore = false
|
||||
break
|
||||
}
|
||||
|
||||
result?.itemList?.forEach((v: any) => {
|
||||
const statsAuthor: StatisticsAuthorLiked = {
|
||||
likeCount: v.authorStats.diggCount,
|
||||
@ -235,6 +235,11 @@ const requestUserLiked = async (
|
||||
: undefined)) ||
|
||||
undefined
|
||||
})
|
||||
|
||||
if (data === "") {
|
||||
throw new Error("Empty response")
|
||||
}
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
if (attempt === 3) {
|
||||
@ -244,7 +249,7 @@ const requestUserLiked = async (
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 3,
|
||||
retries: 10,
|
||||
minTimeout: 1000,
|
||||
maxTimeout: 5000,
|
||||
factor: 2
|
||||
|
||||
@ -30,6 +30,12 @@ export const getUserPosts = (
|
||||
const secUid = res.result.user.secUid
|
||||
const data = await parseUserPosts(secUid, postLimit, proxy)
|
||||
|
||||
if (!data.length)
|
||||
return resolve({
|
||||
status: "error",
|
||||
message: "User not found!"
|
||||
})
|
||||
|
||||
resolve({
|
||||
status: "success",
|
||||
result: data,
|
||||
@ -71,12 +77,6 @@ const parseUserPosts = async (
|
||||
// Prevent missing response posts
|
||||
result = await requestUserPosts(proxy, xttparams)
|
||||
|
||||
// Validate
|
||||
if (result === "") {
|
||||
hasMore = false
|
||||
break
|
||||
}
|
||||
|
||||
result?.itemList?.forEach((v: any) => {
|
||||
const author: AuthorPost = {
|
||||
id: v.author.id,
|
||||
@ -189,7 +189,11 @@ const requestUserPosts = async (
|
||||
undefined
|
||||
}
|
||||
)
|
||||
console.log(data)
|
||||
|
||||
if (data === "") {
|
||||
throw new Error("Empty response")
|
||||
}
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
if (
|
||||
@ -203,7 +207,7 @@ const requestUserPosts = async (
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 3,
|
||||
retries: 10,
|
||||
minTimeout: 1000,
|
||||
maxTimeout: 5000,
|
||||
factor: 2,
|
||||
|
||||
@ -113,6 +113,9 @@ export const SearchLive = async (
|
||||
result.push({ roomInfo, liveInfo })
|
||||
})
|
||||
|
||||
if (!result.length)
|
||||
return resolve({ status: "error", message: "Live not found!" })
|
||||
|
||||
resolve({
|
||||
status: "success",
|
||||
result,
|
||||
|
||||
@ -84,6 +84,9 @@ export const SearchUser = (
|
||||
})
|
||||
}
|
||||
|
||||
if (!result.length)
|
||||
return resolve({ status: "error", message: "User not found!" })
|
||||
|
||||
resolve({
|
||||
status: "success",
|
||||
result,
|
||||
|
||||
@ -116,6 +116,9 @@ export const SearchVideo = async (
|
||||
})
|
||||
})
|
||||
|
||||
if (!result.length)
|
||||
return resolve({ status: "error", message: "Video not found!" })
|
||||
|
||||
resolve({
|
||||
status: "success",
|
||||
result,
|
||||
@ -158,13 +161,18 @@ const requestVideoSearch = async (
|
||||
undefined
|
||||
}
|
||||
)
|
||||
|
||||
if (data === "") {
|
||||
throw new Error("Empty response")
|
||||
}
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 3,
|
||||
retries: 10,
|
||||
minTimeout: 1000,
|
||||
maxTimeout: 5000,
|
||||
factor: 2,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user