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