-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add artstation (#14075)
* feat(route): add artstation * fix: update template * docs: add docs
- Loading branch information
Showing
6 changed files
with
140 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/:handle': ['TonyRL'], | ||
}; |
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,13 @@ | ||
module.exports = { | ||
'artstation.com': { | ||
_name: 'ArtStation', | ||
www: [ | ||
{ | ||
title: 'Artist Profolio', | ||
docs: 'https://docs.rsshub.app/picture#artstation', | ||
source: ['/:handle'], | ||
target: '/artstation/:handle', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = (router) => { | ||
router.get('/:handle', require('./user')); | ||
}; |
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,17 @@ | ||
{{ if description }} | ||
{{@ description }}<br> | ||
{{ /if }} | ||
|
||
{{ if image }} | ||
<img src="{{ image.src }}" alt="{{ image.title }}"> | ||
{{ /if }} | ||
|
||
{{ if assets }} | ||
{{ each assets a }} | ||
{{ if (a.asset_type === 'video' || a.asset_type === 'video_clip') && a.player_embedded }} | ||
{{@ a.player_embedded }}<br> | ||
{{ else if a.asset_type === 'image' || a.asset_type === 'cover' }} | ||
<img src="{{ a.image_url }}"><br> | ||
{{ /if }} | ||
{{ /each }} | ||
{{ /if }} |
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,98 @@ | ||
const got = require('@/utils/got'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const { join } = require('path'); | ||
const { art } = require('@/utils/render'); | ||
const config = require('@/config').value; | ||
|
||
module.exports = async (ctx) => { | ||
const { handle } = ctx.params; | ||
|
||
const headers = { | ||
accept: 'application/json, text/plain, */*', | ||
'accept-language': 'en-US,en;q=0.9', | ||
'content-type': 'application/json', | ||
'user-agent': config.trueUA, | ||
}; | ||
|
||
const csrfToken = await ctx.cache.tryGet('artstation:csrfToken', async () => { | ||
const tokenResponse = await got.post('https://www.artstation.com/api/v2/csrf_protection/token.json', { | ||
headers, | ||
}); | ||
return tokenResponse.headers['set-cookie'][0].split(';')[0].split('=')[1]; | ||
}); | ||
|
||
const { data: userData } = await got(`https://www.artstation.com/users/${handle}/quick.json`, { | ||
headers: { | ||
...headers, | ||
cookie: `PRIVATE-CSRF-TOKEN=${csrfToken}`, | ||
}, | ||
}); | ||
const { data: projects } = await got(`https://www.artstation.com/users/${handle}/projects.json`, { | ||
headers: { | ||
...headers, | ||
cookie: `PRIVATE-CSRF-TOKEN=${csrfToken}`, | ||
}, | ||
searchParams: { | ||
user_id: userData.id, | ||
page: 1, | ||
}, | ||
}); | ||
|
||
const resolveImageUrl = (url) => url.replace(/\/\d{14}\/small_square\//, '/large/'); | ||
|
||
const list = projects.data.map((item) => ({ | ||
title: item.title, | ||
description: art(join(__dirname, 'templates/description.art'), { | ||
description: item.description, | ||
image: { | ||
src: resolveImageUrl(item.cover.small_square_url), | ||
title: item.title, | ||
}, | ||
}), | ||
pubDate: parseDate(item.published_at), | ||
updated: parseDate(item.updated_at), | ||
link: item.permalink, | ||
author: userData.full_name, | ||
assetsCount: item.assets_count, | ||
hashId: item.hash_id, | ||
icons: item.icons, | ||
})); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
if (item.assetsCount > 1 || !item.icons.image) { | ||
const { data } = await got(`https://www.artstation.com/projects/${item.hashId}.json`, { | ||
headers: { | ||
...headers, | ||
cookie: `PRIVATE-CSRF-TOKEN=${csrfToken}`, | ||
}, | ||
}); | ||
|
||
item.description = art(join(__dirname, 'templates/description.art'), { | ||
description: data.description, | ||
assets: data.assets, | ||
}); | ||
|
||
for (const a of data.assets) { | ||
if (a.asset_type !== 'video' && a.asset_type !== 'image' && a.asset_type !== 'video_clip' && a.asset_type !== 'cover') { | ||
throw Error(`Unhandle asset type: ${a.asset_type}`); // model3d, marmoset, pano | ||
} | ||
} | ||
} | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `${userData.full_name} - ArtStation`, | ||
description: userData.headline, | ||
link: userData.permalink, | ||
logo: userData.large_avatar_url, | ||
icon: userData.large_avatar_url, | ||
image: userData.default_cover_url, | ||
item: items, | ||
}; | ||
}; |
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