Files
RSSHub/lib/routes/makerworld/utils.ts
T
dependabot[bot]andTonyRL 6bce9493b5 chore(deps-dev): bump eslint-plugin-unicorn from 71.1.0 to 72.0.0 (#22723)
* chore(deps-dev): bump eslint-plugin-unicorn from 71.1.0 to 72.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 71.1.0 to 72.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v71.1.0...v72.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 72.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* style: fix prefer-dom-node-html-methods

* style: fix prefer-split-limit

* style: fix no-unnecessary-string-trim

* style: fix no-multiple-promise-resolver-calls

* style: add v72 preset

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2026-07-15 23:11:15 +08:00

40 lines
1.7 KiB
TypeScript

import { load } from 'cheerio';
import cache from '@/utils/cache';
import { getPlaywrightPage } from '@/utils/playwright';
export const baseUrl = 'https://makerworld.com';
// makerworld.com sits behind a Cloudflare bot-management challenge that fingerprints the
// TLS/HTTP client itself rather than just headers, so a plain fetch always gets a 403 no
// matter what headers are sent. A real (stealth-patched) browser is required to pass it.
const fetchViaBrowser = async (url: string, type: 'html' | 'json' = 'html') => {
const { page, destroy } = await getPlaywrightPage(url, {
onBeforeLoad: async (page) => {
const expectResourceTypes = new Set(['document', 'script', 'xhr', 'fetch']);
await page.route('**/*', (route) => {
const request = route.request();
expectResourceTypes.has(request.resourceType()) ? route.continue() : route.abort();
});
},
});
try {
return (await page.evaluate(type === 'html' ? () => document.documentElement.getHTML() : () => document.documentElement.textContent)) ?? '';
} finally {
await destroy();
}
};
export const fetchJson = async (url: string, query?: Record<string, string>) => {
const finalUrl = query ? `${url}?${new URLSearchParams(query).toString()}` : url;
return JSON.parse(await fetchViaBrowser(finalUrl, 'json'));
};
export const getNextBuildId = () =>
cache.tryGet('makerworld:nextBuildId', async () => {
const response = await fetchViaBrowser(`${baseUrl}/en`);
const $ = load(response);
const nextData = JSON.parse($('script#__NEXT_DATA__').text());
return nextData.buildId;
});