feat(route): add makerworld (#19434)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { baseUrl, getNextBuildId } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/contests',
|
||||
categories: ['design'],
|
||||
example: '/makerworld/contests',
|
||||
name: 'Contests',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
radar: [
|
||||
{
|
||||
source: ['makerworld.com/:lang/contests'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const nextBuildId = await getNextBuildId();
|
||||
const response = await ofetch(`${baseUrl}/_next/data/${nextBuildId}/en/contests.json`, {
|
||||
headers: {
|
||||
'User-Agent': config.trueUA,
|
||||
},
|
||||
});
|
||||
const { listConst, previewList } = response.pageProps;
|
||||
|
||||
const items = [
|
||||
...listConst.map((c) => ({
|
||||
title: c.contestName,
|
||||
link: `${baseUrl}/en/contests/${c.id}?name=${c.contestName}`,
|
||||
description: c.themeDesc,
|
||||
pubDate: parseDate(c.startTime),
|
||||
})),
|
||||
...previewList.map((p) => ({
|
||||
title: p.contestTheme,
|
||||
description: p.themeDesc,
|
||||
pubDate: parseDate(p.contestTime),
|
||||
})),
|
||||
];
|
||||
|
||||
return {
|
||||
title: 'Contest - MakerWorld',
|
||||
description: 'Join the contest to showcase your creativity and win substantial rewards',
|
||||
link: `${baseUrl}/en/contests`,
|
||||
image: `${baseUrl}/favicon_new.png`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'MakerWorld',
|
||||
url: 'makerworld.com',
|
||||
lang: 'en',
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { baseUrl, getNextBuildId } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/trending',
|
||||
categories: ['design'],
|
||||
example: '/makerworld/trending',
|
||||
name: 'Trending Models',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
radar: [
|
||||
{
|
||||
source: ['makerworld.com/:lang'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const nextBuildId = await getNextBuildId();
|
||||
const response = await ofetch(`${baseUrl}/_next/data/${nextBuildId}/en.json`, {
|
||||
headers: {
|
||||
'User-Agent': config.trueUA,
|
||||
},
|
||||
});
|
||||
|
||||
const items = response.pageProps.popularDesignsData.map((d) => ({
|
||||
title: d.title,
|
||||
link: `${baseUrl}/en/models/${d.id}-${d.slug}`,
|
||||
author: d.designCreator.name,
|
||||
category: d.tags,
|
||||
pubDate: parseDate(d.startTime),
|
||||
description: d.designExtension.design_pictures.map((i) => `<figure><img src="${i.url}" alt="${d.name}"><figcaption>${i.name}</figcaption></figure>`).join(''),
|
||||
}));
|
||||
|
||||
return {
|
||||
title: 'Trending Models - MakerWorld',
|
||||
description: 'Leading 3D printing model community for designers and makers. Download thousands of 3D models and stl models for free, and your No.1 option for multicolor 3D models',
|
||||
link: `${baseUrl}/en`,
|
||||
image: `${baseUrl}/favicon_new.png`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { baseUrl, getNextBuildId } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/:handle/upload',
|
||||
categories: ['design'],
|
||||
example: '/makerworld/@Wcad00/upload',
|
||||
parameters: {
|
||||
handle: 'User handle',
|
||||
},
|
||||
name: 'User Uploads',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
radar: [
|
||||
{
|
||||
source: ['makerworld.com/:lang/:handle/upload', 'makerworld.com/:lang/:handle'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const { handle } = ctx.req.param();
|
||||
|
||||
const nextBuildId = await getNextBuildId();
|
||||
const response = await ofetch(`${baseUrl}/_next/data/${nextBuildId}/en/${handle}/upload.json`, {
|
||||
headers: {
|
||||
'User-Agent': config.trueUA,
|
||||
},
|
||||
query: {
|
||||
handle,
|
||||
},
|
||||
});
|
||||
const { userInfo, designs } = response.pageProps;
|
||||
|
||||
const items = designs.map((d) => ({
|
||||
title: d.title,
|
||||
link: `${baseUrl}/en/models/${d.id}-${d.slug}`,
|
||||
pubDate: parseDate(d.createTime),
|
||||
author: d.designCreator.name,
|
||||
category: d.tags,
|
||||
description: d.instances.map((i) => `<figure><img src="${i.cover}" alt="${d.title}"><figcaption>${i.title}</figcaption></figure>`).join(''),
|
||||
}));
|
||||
|
||||
return {
|
||||
title: `${userInfo.name} | Published - MakerWorld`,
|
||||
link: `${baseUrl}/en/${handle}/upload`,
|
||||
description: userInfo.personal.bio,
|
||||
image: userInfo.avatar,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import cache from '@/utils/cache';
|
||||
import { load } from 'cheerio';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const baseUrl = 'https://makerworld.com';
|
||||
|
||||
export const getNextBuildId = () =>
|
||||
cache.tryGet('makerworld:nextBuildId', async () => {
|
||||
const response = await ofetch(`${baseUrl}/en`, {
|
||||
headers: {
|
||||
'User-Agent': config.trueUA,
|
||||
},
|
||||
});
|
||||
const $ = load(response);
|
||||
const nextData = JSON.parse($('script#__NEXT_DATA__').text());
|
||||
return nextData.buildId;
|
||||
});
|
||||
Reference in New Issue
Block a user