-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add OpenCollective provider #10
Conversation
1781a24
to
060f7cd
Compare
@GeopJr Is this PR ready? I'd love to use it! |
Kinda - I just fixed the conflicts. The main problem still is the lack of default avatar (#11). As per the original post, OpenCollective returns an avatar url even if the user doesn't have one (e.g. https://images.opencollective.com/kentcdodds/d219cb9/avatar/460.png) which causes sponsorkit to fail during the avatar downloading portion: FetchError: 404 Not Found (https://images.opencollective.com/kentcdodds/d219cb9/avatar/460.png) However here's a quick (and dirty) workaround (it's a git patch): diff --git a/src/image.ts b/src/image.ts
index 911f31a..faf7e23 100644
--- a/src/image.ts
+++ b/src/image.ts
@@ -5,8 +5,15 @@ import sharp from 'sharp'
import type { Sponsorship } from './types'
export async function resolveAvatars(ships: Sponsorship[]) {
- return Promise.all(ships.map(async(ship) => {
- const data = await $fetch(ship.sponsor.avatarUrl, { responseType: 'arrayBuffer' })
+ const defaultAvatar = await $fetch("https://i.imgur.com/nk8ksF0.png", { responseType: 'arrayBuffer' })
+ return Promise.all(ships.map(async (ship) => {
+ let data;
+ try {
+ data = await $fetch(ship.sponsor.avatarUrl, { responseType: 'arrayBuffer' })
+ } catch {
+ data = defaultAvatar
+ }
+
const radius = ship.sponsor.type === 'User' ? 0.5 : 0.15
ship.sponsor.avatarUrlHighRes = await imageDataURI.encode(await round(data, radius, 120), 'PNG')
ship.sponsor.avatarUrlMediumRes = await imageDataURI.encode(await round(data, radius, 80), 'PNG') This will use a quick default avatar I made from the GitHub "private sponsor" icon when an avatar 404s. Here's the full example usage: |
I think we could have an option to configure the fallback avatar (could be a function for generated ones). Using GH's fallback one as the default sounds good to me |
Since #11 is done, I think this PR is ready for review! |
docs: GitHub slug -> GitHub handle
This PR adds an OpenCollective provider.
Blocking
OpenCollective returns an avatar url even if the user doesn't have one (which fails onresolveAvatars
), a default one should be provided instead.Concerns
monthlyDollars
Output (on
babel
with a 10 backers hard limit):closes: #8