feat(plugins/sponsors): add new sponsors plugin (#548)
This commit is contained in:
26
source/plugins/sponsors/index.mjs
Normal file
26
source/plugins/sponsors/index.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.sponsors))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
const {sections} = await imports.metadata.plugins.sponsors.inputs({data, account, q})
|
||||
|
||||
//Query sponsors and goal
|
||||
const {[account]:{sponsorsListing:{fullDescription, activeGoal}, sponsorshipsAsMaintainer:{nodes, totalCount:count}}} = await graphql(queries.sponsors({login, account}))
|
||||
const about = await imports.markdown(fullDescription, {mode:"multiline"})
|
||||
const goal = activeGoal ? {progress:activeGoal.percentComplete, title:activeGoal.title, description:await imports.markdown(activeGoal.description)} : null
|
||||
const list = nodes.map(({sponsorEntity:{login, avatarUrl}, tier:{monthlyPriceInDollars:amount}}) => ({login, avatarUrl, amount}))
|
||||
await Promise.all(list.map(async user => user.avatar = await imports.imgb64(user.avatarUrl)))
|
||||
|
||||
//Results
|
||||
return {sections, about, list, count, goal}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user