Skip to content

Commit

Permalink
add support for yuque and juejin (spencerwooo#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
HardwayLinka authored Jan 8, 2023
1 parent a1d6024 commit 2ead278
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Get started

> sub · stats /səb ˈ stats/
>
> - a serverless api for getting the number of followers of you in your favourite services
_*Version 2.0 is still in `beta`, not all features are ported from 1.0. Check below for details 👇_
Expand Down Expand Up @@ -56,6 +57,8 @@ Of course! And as a matter of fact, substats works quite well with [`shields.io`
[![Steam](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.swo.moe%2Fstats%2Fsteamgames%2F76561198336249957&query=count&color=0b1a37&label=Steam&labelColor=134375&logo=steam&suffix=+games&cacheSeconds=3600)](https://steamcommunity.com/profiles/76561198336249957)
[![知乎](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.swo.moe%2Fstats%2Fzhihu%2Fbi-xiao-tian-99&query=count&color=282c34&label=%E7%9F%A5%E4%B9%8E&labelColor=0084ff&logo=zhihu&logoColor=ffffff&suffix=+%E5%85%B3%E6%B3%A8&cacheSeconds=3600)](https://www.zhihu.com/people/bi-xiao-tian-99)
[![哔哩哔哩](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.swo.moe%2Fstats%2Fbilibili%2F401742377&query=count&color=282c34&label=%E5%93%94%E5%93%A9%E5%93%94%E5%93%A9&labelColor=FE7398&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAD7ElEQVR4nO2dW9WrMBCFK6ESkFAJSKiESqgEHCABCZWAhEpAAhL2ecik5dDc%2FpXLBDLfWnlqy0xmJ5BMQnq5CIIgCIIgCIIgCIIgCEIBAHQAemYfrgCunD6wAKAHsEKxALgx+bCQD8%2FS9tmgVqeDr1lLigDg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7efENZLJpgPSw0pfz0cdt4U3230Td%2FTvx2R6d2FrHhEWLkq5PELOMsRPHCPnAZGv1xJteL7jbJiaW3sB2nDvPC%2FosSYvjRQz4cJ6n7KO3rYQL7M+L6nVtfDVRAEQRAEQRAEQRAEIZ5%2FSAXmdfXaoQsAAAAASUVORK5CYII%3D&suffix=+%E5%85%B3%E6%B3%A8&cacheSeconds=3600)](https://space.bilibili.com/401742377)
[![掘金](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.swo.moe%2Fstats%2Fjuejin%2F1838039172387262&query=count&color=282c34&label=%E6%8E%98%E9%87%91&labelColor=1e80ff&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzYiIGhlaWdodD0iMjgiIHZpZXdCb3g9IjAgMCAzNiAyOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNy41ODc1IDYuNzcyNjhMMjEuODIzMiAzLjQwNTA1TDE3LjU4NzUgMC4wMDc0ODIzN0wxNy41ODM3IDBMMTMuMzU1NSAzLjM5NzU3TDE3LjU4MzcgNi43Njg5NEwxNy41ODc1IDYuNzcyNjhaTTE3LjU4NjMgMTcuMzk1NUgxNy41OUwyOC41MTYxIDguNzc0MzJMMjUuNTUyNiA2LjM5NDUzTDE3LjU5IDEyLjY4MDhIMTcuNTg2M0wxNy41ODI1IDEyLjY4NDVMOS42MTk5MyA2LjQwMjAxTDYuNjYwMTYgOC43ODE4MUwxNy41ODI1IDE3LjM5OTJMMTcuNTg2MyAxNy4zOTU1Wk0xNy41ODI4IDIzLjI4OTFMMTcuNTg2NSAyMy4yODU0TDMyLjIxMzMgMTEuNzQ1NkwzNS4xNzY4IDE0LjEyNTRMMjguNTIzOCAxOS4zNzUyTDE3LjU4NjUgMjhMMC4yODQzNzYgMTQuMzU3NEwwIDE0LjEyOTFMMi45NTk3NyAxMS43NTMxTDE3LjU4MjggMjMuMjg5MVoiIGZpbGw9IiMxRTgwRkYiLz4KPC9zdmc+Cg==&logoColor=ffffff&suffix=+%E5%85%B3%E6%B3%A8&cacheSeconds=3600)](https://juejin.cn/user/1838039172387262)
[![语雀](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.swo.moe%2Fstats%2Fyuque%2F85213&query=count&color=2CA5E0&label=%E8%AF%AD%E9%9B%80&labelColor=36d07c&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTc2IiBoZWlnaHQ9IjE3MiIgdmlld0JveD0iMCAwIDE3NiAxNzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxyYWRpYWxHcmFkaWVudCBjeD0iMzguMTc1JSIgY3k9Ijg2LjA3OCUiIGZ4PSIzOC4xNzUlIiBmeT0iODYuMDc4JSIgcj0iOTcuMDY3JSIgZ3JhZGllbnRUcmFuc2Zvcm09InNjYWxlKC44NTUzNyAxKSByb3RhdGUoLTQ2LjMwMSAuNDE0IC43ODUpIiBpZD0iYiI+PHN0b3Agc3RvcC1jb2xvcj0iIzE3OEY2NyIgb2Zmc2V0PSIwJSIvPjxzdG9wIHN0b3AtY29sb3I9IiMzMUNDNzkiIHN0b3Atb3BhY2l0eT0iLjU1IiBvZmZzZXQ9IjU0LjY4NSUiLz48c3RvcCBzdG9wLWNvbG9yPSIjNTNFNjhEIiBzdG9wLW9wYWNpdHk9Ii44IiBvZmZzZXQ9IjEwMCUiLz48L3JhZGlhbEdyYWRpZW50PjxwYXRoIGQ9Ik03Ni41NjcgMGgxLjA2NWwuNTA5LjAwMy41MTkuMDAyLjUyOC4wMDQuNTM4LjAwNS41NDcuMDA2LjU1Ni4wMDcuMzc2LjAwNS4zOC4wMDYuNTc4LjAxLjU4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NhIi8+PHVzZSBmaWxsLW9wYWNpdHk9Ii42IiBmaWxsPSJ1cmwoI2IpIiB4bGluazpocmVmPSIjYSIvPjwvZz48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxNy45MzMgMzAuMTM1KSI+PHVzZSBmaWxsPSIjOTNFNjVDIiB4bGluazpocmVmPSIjYyIvPjx1c2UgZmlsbC1vcGFjaXR5PSIuNzUiIGZpbGw9InVybCgjZCkiIHN0eWxlPSJtaXgtYmxlbmQtbW9kZTpvdmVybGF5IiB4bGluazpocmVmPSIjYyIvPjwvZz48L2c+PC9zdmc+&suffix=+%E5%85%B3%E6%B3%A8&cacheSeconds=3600)](https://www.yuque.com/lyndon)

You can easily create your own badge with our badge builder at [substats.swo.moe](https://substats.swo.moe/).

Expand Down Expand Up @@ -134,6 +137,8 @@ Try our `/common` route API URL builder here: [substats.swo.moe/common](https://
- weibo
- wikipediazh
- zhihu
- juejin
- yuque

<a href="https://api.swo.moe/stats/afdian/afdian"><img src="docs/public/assets/sources/logo_afdian.png" width="auto" height="64px" alt="logo_afdian" /></a>
<a href="https://api.swo.moe/stats/bilibili/401742377"><img src="docs/public/assets/sources/logo_bilibili.png" width="auto" height="64px" alt="logo_bilibili" /></a>
Expand All @@ -156,6 +161,8 @@ Try our `/common` route API URL builder here: [substats.swo.moe/common](https://
<a href="https://api.swo.moe/stats/weibo/5648729445"><img src="docs/public/assets/sources/logo_weibo.png" width="auto" height="64px" alt="logo_weibo" /></a>
<a href="https://api.swo.moe/stats/wikipediazh/ChenSimon"><img src="docs/public/assets/sources/logo_wikipedia.png" width="auto" height="64px" alt="logo_wikipedia" /></a>
<a href="https://api.swo.moe/stats/zhihu/bi-xiao-tian-99"><img src="docs/public/assets/sources/logo_zhihu.png" width="auto" height="64px" alt="logo_zhihu" /></a>
<a href="https://api.swo.moe/stats/juejin/1838039172387262"><img src="docs/public/assets/sources/logo_juejin.png" width="auto" height="64px" alt="logo_juejin" /></a>
<a href="https://api.swo.moe/stats/yuque/lyndon"><img src="docs/public/assets/sources/logo_yuque.png" width="auto" height="64px" alt="logo_yuque" /></a>

## What's new?

Expand Down
Binary file added docs/public/assets/sources/logo_juejin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/sources/logo_yuque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions docs/src/sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,36 @@ export const availableSources = [
link: (k: string) => `https://www.zhihu.com/people/${k}`,
},
},
{
source: 'juejin',
icon: '/assets/sources/logo_juejin.png',
description: '掘金 - articles、文章',
warning: '',
helper: <HelperText source="掘金" uid="1838039172387262" url="https://juejin.cn/user/1838039172387262" />,
badge: {
label: '掘金',
labelColor: '1e80ff',
logo: 'juejin',
logoColor: 'ffffff',
suffix: '关注',
color: '282c34',
link: (k: string) => `https://juejin.cn/user/${k}`,
},
},
{
source: 'yuque',
icon: '/assets/sources/logo_yuque.png',
description: '语雀 - articles、文章',
warning: '',
helper: <HelperText source="语雀" uid="lyndon" url="https://www.yuque.com/lyndon" />,
badge: {
label: '语雀',
labelColor: '36d07c',
logo: 'yuque',
logoColor: 'ffffff',
suffix: '关注',
color: '282c34',
link: (k: string) => `https://www.yuque.com/${k}`,
},
},
]
4 changes: 4 additions & 0 deletions worker/src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import weiboProvider from './weibo'
import wikipediaZhProvider from './wikipedia'
import zhihuProvider from './zhihu'
import instagramProvider from './instagram'
import juejinProvider from './juejin'
import yuqueProvider from './yuque'

type FailedSubstatsResponse = Extract<SubstatsResponse, { failed: true }>

Expand Down Expand Up @@ -161,5 +163,7 @@ export default function getProviders(): Record<
weibo: weiboProvider,
wikipediazh: wikipediaZhProvider,
zhihu: zhihuProvider,
juejin: juejinProvider,
yuque: yuqueProvider,
}
}
25 changes: 25 additions & 0 deletions worker/src/providers/juejin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SubstatsResponse } from '@/types'
import { commonProviderHandler } from '.'

// https://juejin.cn/user/1838039172387262
type JuejinResponse =
{
err_no: number;
err_msg: string;
data: {
follower_count: number
}
}

export default async function juejinProvider(
key: string,
): Promise<SubstatsResponse> {
return commonProviderHandler<JuejinResponse>({
providerName: 'juejin',
queryKey: key,
fetchUrl: `https://api.juejin.cn/user_api/v1/user/get?user_id=${key}`,
countObjPath: 'data.follower_count',
errorMessageObjPath: 'err_msg',
isResponseValid: d => 'follower_count' in d.data,
})
}
23 changes: 23 additions & 0 deletions worker/src/providers/yuque.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { SubstatsResponse } from '@/types'
import { commonProviderHandler } from '.'

// https://www.yuque.com/lyndon
type YuqueResponse =
{
data: {
followers_count: number
}
}

export default async function yuqueProvider(
key: string,
): Promise<SubstatsResponse> {
return commonProviderHandler<YuqueResponse>({
providerName: 'yuque',
queryKey: key,
fetchUrl: `https://www.yuque.com/api/users/${key}/profile?`,
countObjPath: 'data.followers_count',
errorMessageObjPath: '',
isResponseValid: d => 'followers_count' in d.data,
})
}
2 changes: 2 additions & 0 deletions worker/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export type SupportedProviders =
| 'weibo'
| 'wikipediazh'
| 'zhihu'
| 'juejin'
| 'yuque'

0 comments on commit 2ead278

Please sign in to comment.