-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
857 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function formatNumberWithLabel(number: number): string { | ||
if (number < 1_000) { | ||
return number.toString(); | ||
} | ||
|
||
const units = ["K", "M", "B"]; | ||
const threshold = 1_000; | ||
|
||
let unitIndex = -1; | ||
let scaledNumber = number; | ||
|
||
while (scaledNumber >= threshold && unitIndex < units.length - 1) { | ||
scaledNumber /= threshold; | ||
unitIndex++; | ||
} | ||
|
||
const formattedNumber = | ||
scaledNumber % 1 === 0 ? scaledNumber.toFixed(0) : scaledNumber.toFixed(1); | ||
|
||
return `${formattedNumber}${units[unitIndex]}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./formatDate"; | ||
export * from "./formatNumbers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import request from "../fetch/request"; | ||
import { CommentsResultResponse } from "../interfaces"; | ||
import { parseCommentsResponse } from "../parser/parse.comments"; | ||
|
||
const AGGREGATED_PIN_ID: string = `5345354990309401472`; | ||
|
||
interface IOptions { | ||
id: string; | ||
pageSize?: number; | ||
} | ||
|
||
export async function getComments( | ||
options: IOptions | ||
): Promise<CommentsResultResponse[]> { | ||
const params = { | ||
source_url: `/pin/${options.id}/`, | ||
data: { | ||
options: { | ||
aggregated_pin_id: AGGREGATED_PIN_ID, | ||
comment_featured_ids: [], | ||
page_size: options?.pageSize || 20, | ||
redux_normalize_feed: true, | ||
is_reversed: false, | ||
}, | ||
context: {}, | ||
}, | ||
}; | ||
|
||
const URL: string = `https://in.pinterest.com/resource/UnifiedCommentsResource/get/?source_url=${encodeURIComponent( | ||
params.source_url | ||
)}&data=${encodeURIComponent(JSON.stringify(params.data))}`; | ||
|
||
const data = await request.get(URL); | ||
return parseCommentsResponse(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { Api } from "../api/api"; | ||
import request from "../fetch/request"; | ||
import { parseSpecificScriptTags } from "../parser/parser.tags"; | ||
import { parsePinData } from "../parser/parese.pin"; | ||
import type { ParsedPinData } from "../interfaces"; | ||
import { PinV4Response } from "../interfaces"; | ||
import { parsePinV4 } from "../parser/parse.pin"; | ||
|
||
export async function getPin(id: string): Promise<ParsedPinData> { | ||
const requestCall = await request.getText(Api.baseURL + `/pin/${id}`); | ||
const response = requestCall; | ||
const parseScriptAllScriptTags = parseSpecificScriptTags(response); | ||
const scriptFormValidation = parseScriptAllScriptTags[0]; | ||
const JSONConversion = JSON.parse(scriptFormValidation); | ||
const data = parsePinData(JSONConversion); | ||
return { ...data }; | ||
export async function getPin<T extends string>(id: T): Promise<PinV4Response> { | ||
const params = { | ||
source_url: `/pin/${id}/`, | ||
data: { | ||
options: { | ||
id: `${id}`, | ||
field_set_key: "auth_web_main_pin", | ||
noCache: true, | ||
fetch_visual_search_objects: true, | ||
}, | ||
context: {}, | ||
}, | ||
}; | ||
|
||
const URL: string = `https://in.pinterest.com/resource/PinResource/get/?source_url=${encodeURIComponent( | ||
params.source_url | ||
)}&data=${encodeURIComponent(JSON.stringify(params.data))}`; | ||
|
||
const data = await request.get(URL); | ||
return parsePinV4(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Api } from "../api/api"; | ||
import request from "../fetch/request"; | ||
import { parseSpecificScriptTags } from "../parser/parser.tags"; | ||
import { parsePinData } from "../parser/parse.pin_v3"; | ||
import type { ParsedPinData } from "../interfaces"; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
export async function getPinV3(id: string): Promise<ParsedPinData> { | ||
const requestCall = await request.getText(Api.baseURL + `/pin/${id}`); | ||
const response = requestCall; | ||
const parseScriptAllScriptTags = parseSpecificScriptTags(response); | ||
const scriptFormValidation = parseScriptAllScriptTags[0]; | ||
const JSONConversion = JSON.parse(scriptFormValidation); | ||
const data = parsePinData(JSONConversion); | ||
return { ...data }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface CommentUser { | ||
username?: string; | ||
displayName?: string; | ||
image?: string; | ||
id?: string; | ||
} | ||
|
||
export interface CommentsResultResponse { | ||
text?: string; | ||
createdAt?: string; | ||
user?: CommentUser; | ||
details?: string; | ||
likes?: number; | ||
image?: string[]; | ||
tags?: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
export interface PinV4Images { | ||
lg?: string; | ||
md?: string; | ||
xl?: string; | ||
og?: string; | ||
} | ||
|
||
export interface PinV4Reactions { | ||
label?: string; | ||
numbers?: number; | ||
} | ||
|
||
export interface PinV4BoardOwner { | ||
id?: string; | ||
username?: string; | ||
fullName?: string; | ||
imageMediumUrl?: string; | ||
isVerifiedMerchant?: boolean; | ||
} | ||
|
||
export interface PinV4Board { | ||
name?: string; | ||
id?: string; | ||
imageThumbnail?: string; | ||
url?: string; | ||
description?: string; | ||
privacy?: string; | ||
isCollaborative?: boolean; | ||
layout?: string; | ||
pinThumbnailUrls?: string[]; | ||
owner?: PinV4BoardOwner; | ||
} | ||
|
||
export interface PinV4Creator { | ||
fullName?: string; | ||
username?: string; | ||
image?: string; | ||
} | ||
|
||
export interface PinV4CarouselSlot { | ||
image?: string; | ||
title?: string; | ||
details?: string; | ||
id?: string; | ||
} | ||
|
||
export interface PinV4Response { | ||
title?: string; | ||
images?: PinV4Images; | ||
id?: string; | ||
video?: string; | ||
reactions?: PinV4Reactions; | ||
commentCount?: number; | ||
category?: string; | ||
board?: PinV4Board; | ||
creator?: PinV4Creator; | ||
description?: string; | ||
createdAt?: string; | ||
shareCount?: number; | ||
repinCount?: number; | ||
favorites?: number; | ||
carousel?: PinV4CarouselSlot[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.