Merge branch 'dev' into docs

This commit is contained in:
William Oldham
2023-09-28 18:52:02 +01:00
committed by GitHub
3 changed files with 47 additions and 25 deletions

63
package-lock.json generated
View File

@@ -12,11 +12,13 @@
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"nanoid": "^5.0.1" "node-fetch": "^2.7.0",
"randombytes": "^2.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",
"@types/node-fetch": "^2.6.6", "@types/node-fetch": "^2.6.6",
"@types/randombytes": "^2.0.1",
"@types/spinnies": "^0.5.1", "@types/spinnies": "^0.5.1",
"@typescript-eslint/eslint-plugin": "^5.60.0", "@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0", "@typescript-eslint/parser": "^5.60.0",
@@ -942,6 +944,15 @@
"form-data": "^4.0.0" "form-data": "^4.0.0"
} }
}, },
"node_modules/@types/randombytes": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/randombytes/-/randombytes-2.0.1.tgz",
"integrity": "sha512-kWMqPyxpTUTofwbGN47MWddBFiJnWJlfLBdDg2NvmZSKHOmKY9ujVA3PIfBgXcIHTCpsqoQqYudBwanFXzGD9A==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/semver": { "node_modules/@types/semver": {
"version": "7.5.0", "version": "7.5.0",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz",
@@ -3501,9 +3512,9 @@
} }
}, },
"node_modules/get-func-name": { "node_modules/get-func-name": {
"version": "2.0.0", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz",
"integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "*" "node": "*"
@@ -4698,23 +4709,6 @@
"url": "https://github.com/sponsors/raouldeheer" "url": "https://github.com/sponsors/raouldeheer"
} }
}, },
"node_modules/nanoid": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.1.tgz",
"integrity": "sha512-vWeVtV5Cw68aML/QaZvqN/3QQXc6fBfIieAlu05m7FZW2Dgb+3f0xc0TTxuJW+7u30t7iSDTV/j3kVI0oJqIfQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"bin": {
"nanoid": "bin/nanoid.js"
},
"engines": {
"node": "^18 || >=20"
}
},
"node_modules/natural-compare": { "node_modules/natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@@ -5262,6 +5256,14 @@
} }
] ]
}, },
"node_modules/randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
"integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==",
"dependencies": {
"safe-buffer": "^5.1.0"
}
},
"node_modules/react-is": { "node_modules/react-is": {
"version": "17.0.2", "version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
@@ -5432,6 +5434,25 @@
"queue-microtask": "^1.2.2" "queue-microtask": "^1.2.2"
} }
}, },
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/safe-regex-test": { "node_modules/safe-regex-test": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz",

View File

@@ -48,6 +48,7 @@
"devDependencies": { "devDependencies": {
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",
"@types/node-fetch": "^2.6.6", "@types/node-fetch": "^2.6.6",
"@types/randombytes": "^2.0.1",
"@types/spinnies": "^0.5.1", "@types/spinnies": "^0.5.1",
"@typescript-eslint/eslint-plugin": "^5.60.0", "@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0", "@typescript-eslint/parser": "^5.60.0",
@@ -77,6 +78,7 @@
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"nanoid": "^5.0.1" "node-fetch": "^2.7.0",
"randombytes": "^2.1.0"
} }
} }

View File

@@ -1,12 +1,11 @@
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import { customAlphabet } from 'nanoid'; import randomBytes from 'randombytes';
import type { ScrapeContext } from '@/utils/context'; import type { ScrapeContext } from '@/utils/context';
import { apiUrls, appId, appKey, key } from './common'; import { apiUrls, appId, appKey, key } from './common';
import { encrypt, getVerify } from './crypto'; import { encrypt, getVerify } from './crypto';
const nanoid = customAlphabet('0123456789abcdef', 32);
const expiry = () => Math.floor(Date.now() / 1000 + 60 * 60 * 12); const expiry = () => Math.floor(Date.now() / 1000 + 60 * 60 * 12);
export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = false) => { export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = false) => {
@@ -40,7 +39,7 @@ export const sendRequest = async (ctx: ScrapeContext, data: object, altApi = fal
formatted.append('platform', 'android'); formatted.append('platform', 'android');
formatted.append('version', '129'); formatted.append('version', '129');
formatted.append('medium', 'Website'); formatted.append('medium', 'Website');
formatted.append('token', nanoid()); formatted.append('token', randomBytes(16).toString('hex'));
const requestUrl = altApi ? apiUrls[1] : apiUrls[0]; const requestUrl = altApi ? apiUrls[1] : apiUrls[0];