Skip to content

Commit

Permalink
fix(afdian): normalize default name and default avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 2, 2024
1 parent a7d7a83 commit ce93d6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/processing/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function resolveAvatars(
const limit = pLimit(15)

return Promise.all(ships.map(ship => limit(async () => {
const data = ship.privacyLevel === 'PRIVATE'
const data = (ship.privacyLevel === 'PRIVATE' || !ship.sponsor.avatarUrl)
? fallbackAvatar
: await $fetch(ship.sponsor.avatarUrl, {
responseType: 'arrayBuffer',
Expand Down
10 changes: 8 additions & 2 deletions src/providers/afdian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ export async function fetchAfdianSponsors(options: SponsorkitConfig['afdian'] =
const current = raw.current_plan
const expireTime = current?.expire_time
const isExpired = expireTime ? expireTime < Date.now() / 1000 : true
let name = raw.user.name
if (name.startsWith('鐖卞彂鐢电敤鎴穇'))
name = raw.user.user_id.slice(0, 5)
let avatarUrl = raw.user.avatar
if (avatarUrl.startsWith('https://pic1.afdiancdn.com/default/avatar/avatar-'))
avatarUrl = undefined
return {
sponsor: {
type: 'User',
login: raw.user.user_id,
name: raw.user.name,
avatarUrl: raw.user.avatar,
name,
avatarUrl,
linkUrl: `https://afdian.net/u/${raw.user.user_id}`,
},
// all_sum_amount is based on cny
Expand Down

0 comments on commit ce93d6a

Please sign in to comment.