From 0343e0cb17bc37f0d80cede5c283d2f7c0ccebdd Mon Sep 17 00:00:00 2001
From: Surmon
Date: Sat, 17 Aug 2024 19:30:57 +0800
Subject: [PATCH] feat: v4.40.0
---
package.json | 2 +-
src/bff.ts | 48 +++----
src/components/widget/sponsor/provider.vue | 15 ++-
src/components/widget/sponsor/state.ts | 6 +-
src/config/bff.yargs.ts | 1 -
src/constants/tunnel.ts | 8 +-
src/pages/about/desktop.vue | 4 +-
src/pages/article/index.vue | 4 +-
src/pages/sponsor.vue | 2 +-
src/server/getters/github.ts | 146 ++++++---------------
src/server/getters/npm.ts | 39 ++++++
src/server/getters/open-srouce.ts | 69 ----------
src/stores/_hook.ts | 10 +-
src/stores/calendar.ts | 3 +-
src/stores/sponsor.ts | 50 -------
src/stores/sponsors.ts | 19 +++
src/stores/statistic.ts | 7 +-
17 files changed, 157 insertions(+), 276 deletions(-)
create mode 100644 src/server/getters/npm.ts
delete mode 100644 src/server/getters/open-srouce.ts
delete mode 100644 src/stores/sponsor.ts
create mode 100644 src/stores/sponsors.ts
diff --git a/package.json b/package.json
index f9ab0d2e..9d83db07 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "surmon.me",
- "version": "4.39.0",
+ "version": "4.40.0",
"description": "Surmon.me blog",
"author": "Surmon",
"license": "MIT",
diff --git a/src/bff.ts b/src/bff.ts
index 811461e2..2f38ff49 100644
--- a/src/bff.ts
+++ b/src/bff.ts
@@ -16,10 +16,10 @@ import { getGTagScript } from './server/getters/gtag'
import { getAllWallpapers } from './server/getters/wallpaper'
import { getMyGoogleMap } from './server/getters/my-google-map'
import { getTwitterProfile, getTwitterTweets } from './server/getters/twitter'
-import { getGitHubSponsors, getGitHubContributions } from './server/getters/github'
import { getInstagramMedias, getInstagramMediaChildren, getInstagramCalendar } from './server/getters/instagram'
import { getYouTubeChannelPlayLists, getYouTubeVideoListByPlayerlistId } from './server/getters/youtube'
-import { getGitHubStatistic, getNPMStatistic } from './server/getters/open-srouce'
+import { getGitHubStatistic, getGitHubSponsors, getGitHubContributions } from './server/getters/github'
+import { getNPMStatistic } from './server/getters/npm'
import { getDoubanMovies } from './server/getters/douban'
import { getSongList } from './server/getters/netease-music'
import { getWebFont, WebFontContentType } from './server/getters/webfont'
@@ -122,20 +122,6 @@ createExpressApp().then(async ({ app, server, cache }) => {
responser(() => getWallpaperCache())
)
- // GitHub sponsors
- const getSponsorsCache = cacher.interval(cache, {
- key: TunnelModule.GitHubSponsors,
- ttl: days(3),
- interval: hours(18),
- retry: minutes(10),
- getter: getGitHubSponsors
- })
-
- app.get(
- `${TUN}/${TunnelModule.GitHubSponsors}`,
- responser(() => getSponsorsCache())
- )
-
// 163 music BGM list
const get163MusicCache = cacher.interval(cache, {
key: TunnelModule.NetEaseMusic,
@@ -240,30 +226,36 @@ createExpressApp().then(async ({ app, server, cache }) => {
})(request, response, next)
})
+ // GitHub sponsors
+ app.get(
+ `${TUN}/${TunnelModule.GitHubSponsors}`,
+ responser(() => {
+ return cacher.passive(cache, {
+ key: TunnelModule.GitHubSponsors,
+ ttl: hours(4),
+ getter: getGitHubSponsors
+ })
+ })
+ )
+
// GitHub contributions
app.get(
`${TUN}/${TunnelModule.GitHubContributions}`,
responser(() => {
return cacher.passive(cache, {
key: TunnelModule.GitHubContributions,
- ttl: hours(8),
- getter: () => {
- const now = new Date()
- const end = now.toISOString()
- now.setFullYear(now.getFullYear() - 1)
- const start = now.toISOString()
- return getGitHubContributions(start, end)
- }
+ ttl: hours(4),
+ getter: getGitHubContributions
})
})
)
// GitHub statistic
app.get(
- `${TUN}/${TunnelModule.OpenSourceGitHubStatistic}`,
+ `${TUN}/${TunnelModule.StatisticGitHubJson}`,
responser(() => {
return cacher.passive(cache, {
- key: TunnelModule.OpenSourceGitHubStatistic,
+ key: TunnelModule.StatisticGitHubJson,
ttl: hours(8),
getter: getGitHubStatistic
})
@@ -272,10 +264,10 @@ createExpressApp().then(async ({ app, server, cache }) => {
// NPM statistic
app.get(
- `${TUN}/${TunnelModule.OpenSourceNPMStatistic}`,
+ `${TUN}/${TunnelModule.StatisticNpmJson}`,
responser(() => {
return cacher.passive(cache, {
- key: TunnelModule.OpenSourceNPMStatistic,
+ key: TunnelModule.StatisticNpmJson,
ttl: hours(8),
getter: getNPMStatistic
})
diff --git a/src/components/widget/sponsor/provider.vue b/src/components/widget/sponsor/provider.vue
index daaa3ffa..22e4853c 100644
--- a/src/components/widget/sponsor/provider.vue
+++ b/src/components/widget/sponsor/provider.vue
@@ -17,12 +17,15 @@
const { isZhLang } = useEnhancer()
const activeProvider = computed(() => props.state.activeProvider.value)
const allGitHubSponsors = computed(() => {
+ if (!props.state.githubSponsors.data) {
+ return []
+ }
return [
- ...props.state.githubSponsor.activeSponsors.map((sponsor) => ({
+ ...props.state.githubSponsors.data.currentSponsors.map((sponsor) => ({
active: true,
_: sponsor
})),
- ...props.state.githubSponsor.inactiveSponsors.map((sponsor) => ({
+ ...props.state.githubSponsors.data.pastSponsors.map((sponsor) => ({
active: false,
_: sponsor
}))
@@ -70,13 +73,13 @@
我在 GitHub Sponsors 累计已得到
- {{ state.githubSponsor.activeSponsors.length }}
- + {{ state.githubSponsor.inactiveSponsors.length }} 位赞助者的支持
+ {{ state.githubSponsors.data?.currentSponsors.length }}
+ + {{ state.githubSponsors.data?.pastSponsors.length }} 位赞助者的支持
I have accumulated
- {{ state.githubSponsor.activeSponsors.length }}
- + {{ state.githubSponsor.inactiveSponsors.length }} backers on GitHub Sponsors
+ {{ state.githubSponsors.data?.currentSponsors.length }}
+ + {{ state.githubSponsors.data?.pastSponsors.length }} backers on GitHub Sponsors
diff --git a/src/components/widget/sponsor/state.ts b/src/components/widget/sponsor/state.ts
index 06c8bcee..720fdda1 100644
--- a/src/components/widget/sponsor/state.ts
+++ b/src/components/widget/sponsor/state.ts
@@ -1,7 +1,7 @@
import { ref, computed } from 'vue'
import { useEnhancer } from '/@/app/enhancer'
import { GAEventCategories } from '/@/constants/gtag'
-import { useSponsorStore } from '/@/stores/sponsor'
+import { useGitHubSponsorsStore } from '/@/stores/sponsors'
import { IDENTITIES, VALUABLE_LINKS } from '/@/config/app.config'
export enum ProviderId {
@@ -60,7 +60,7 @@ export const PROVIDERS = [
export type SponsorState = ReturnType
export const useSponsorState = (initId?: ProviderId) => {
const { gtag } = useEnhancer()
- const githubSponsor = useSponsorStore()
+ const githubSponsors = useGitHubSponsorsStore()
const activeId = ref(initId && PROVIDER_IDS.includes(initId) ? initId : PROVIDERS[0].id)
const activeProvider = computed(() => PROVIDERS.find((t) => t.id === activeId.value)!)
@@ -77,6 +77,6 @@ export const useSponsorState = (initId?: ProviderId) => {
activeId,
activeProvider,
setProviderId,
- githubSponsor
+ githubSponsors
}
}
diff --git a/src/config/bff.yargs.ts b/src/config/bff.yargs.ts
index 3469128e..6bb087fe 100644
--- a/src/config/bff.yargs.ts
+++ b/src/config/bff.yargs.ts
@@ -7,7 +7,6 @@
import yargs from 'yargs'
const argv = yargs(process.argv.slice(2)).argv
-export const GITHUB_BEARER_TOKEN = argv.github_token
export const INSTAGRAM_TOKEN = argv.instagram_token
export const YOUTUBE_API_KEY = argv.youtube_token
export const TWITTER_COOKIE = argv.twitter_cookie
diff --git a/src/constants/tunnel.ts b/src/constants/tunnel.ts
index 50daeedc..d1b588fc 100644
--- a/src/constants/tunnel.ts
+++ b/src/constants/tunnel.ts
@@ -16,10 +16,10 @@ export enum TunnelModule {
InstagramMediaChildren = 'instagram_media_children',
InstagramCalendar = 'instagram_calendar',
BingWallpaper = 'bing_wallpaper',
- GitHubSponsors = 'github_sponsors',
- GitHubContributions = 'github_contributions',
NetEaseMusic = 'netease_music',
DoubanMovies = 'douban_movies',
- OpenSourceGitHubStatistic = 'open_source_github_statistic',
- OpenSourceNPMStatistic = 'open_source_npm_statistic'
+ GitHubSponsors = 'github_sponsors',
+ GitHubContributions = 'github_contributions',
+ StatisticGitHubJson = 'statistic_github_json',
+ StatisticNpmJson = 'statistic_npm_json'
}
diff --git a/src/pages/about/desktop.vue b/src/pages/about/desktop.vue
index 3c1cf5db..d8abaabb 100755
--- a/src/pages/about/desktop.vue
+++ b/src/pages/about/desktop.vue
@@ -19,7 +19,7 @@
import { useAboutPageMeta, useAdminAvatar, i18ns, SPECIAL_LINKS } from './shared'
const { gtag, gState, isZhLang, cdnDomain } = useEnhancer()
- const { adminInfo, appOption, sponsor } = useStores()
+ const { adminInfo, appOption, githubSponsors } = useStores()
const handleGTagEvent = (event: string) => {
gtag?.event(event, {
@@ -43,7 +43,7 @@
}
const handleSponsor = () => {
- sponsor.fetch()
+ githubSponsors.fetch()
gState.toggleSwitcher('sponsor', true)
handleGTagEvent('sponsor_modal')
}
diff --git a/src/pages/article/index.vue b/src/pages/article/index.vue
index 259c28e6..896c2dff 100755
--- a/src/pages/article/index.vue
+++ b/src/pages/article/index.vue
@@ -30,7 +30,7 @@
}>()
const { i18n: _i18n, head, seoMeta, route, gtag, gState } = useEnhancer()
- const { identity, sponsor, comment: commentStore, articleDetail: articleDetailStore } = useStores()
+ const { identity, githubSponsors, comment: commentStore, articleDetail: articleDetailStore } = useStores()
const { article, fetching, prevArticle, nextArticle, relatedArticles } = storeToRefs(articleDetailStore)
const isLiked = computed(() => Boolean(article.value && identity.isLikedPage(article.value.id)))
const articleExtends = computed(() => article.value?.extends || [])
@@ -54,7 +54,7 @@
}
const handleSponsor = () => {
- sponsor.fetch()
+ githubSponsors.fetch()
gState.toggleSwitcher('sponsor', true)
gtag?.event('article_sponsor', {
event_category: GAEventCategories.Article
diff --git a/src/pages/sponsor.vue b/src/pages/sponsor.vue
index bd106b5c..f8b23f2b 100755
--- a/src/pages/sponsor.vue
+++ b/src/pages/sponsor.vue
@@ -18,7 +18,7 @@
})
onBeforeMount(() => {
- sponsorState.githubSponsor.fetch()
+ sponsorState.githubSponsors.fetch()
})
onMounted(() => {
diff --git a/src/server/getters/github.ts b/src/server/getters/github.ts
index c49b1af8..c6bd189b 100644
--- a/src/server/getters/github.ts
+++ b/src/server/getters/github.ts
@@ -6,28 +6,33 @@
import axios from '@/server/services/axios'
import { IDENTITIES } from '@/config/app.config'
-import { GITHUB_BEARER_TOKEN } from '@/config/bff.yargs'
-const graphqlGitHub = (query: string): Promise => {
- return axios
- .request({
- // https://github.com/settings/tokens
- headers: { Authorization: `bearer ${GITHUB_BEARER_TOKEN}` },
- url: `https://api.github.com/graphql`,
- method: 'POST',
- data: JSON.stringify({
- query: `query {
- user(login: "${IDENTITIES.GITHUB_USER_NAME}") {
- ${query}
- }
- }`
- })
- })
- .then((response) => {
- return response.data.errors
- ? Promise.reject(response.data.errors.map((error) => error.message).join('; '))
- : Promise.resolve(response.data.data.user)
- })
+export const fetchGitHubStatisticJSON = async (fileName: string): Promise => {
+ const url = `https://raw.githubusercontent.com/${IDENTITIES.GITHUB_USER_NAME}/${IDENTITIES.GITHUB_USER_NAME}/release/${fileName}`
+ const response = await axios.get(url, { timeout: 6000 })
+ return response.data
+}
+
+export interface GitHubStatistic {
+ followerCount: number
+ followingCount: number
+ gistCount: number
+ repositoryCount: number
+ organizationCount: number
+ totalStarCount: number
+ totalCodeSize: number
+}
+
+export const getGitHubStatistic = () => {
+ return fetchGitHubStatisticJSON('github.json').then((data) => ({
+ followerCount: data.userinfo.followers,
+ followingCount: data.userinfo.following,
+ gistCount: data.userinfo.public_gists,
+ repositoryCount: data.userinfo.public_repos,
+ organizationCount: data.organizations.length,
+ totalStarCount: data.statistics.stars,
+ totalCodeSize: data.statistics.size
+ }))
}
export interface GitHubSponsorUser {
@@ -39,94 +44,29 @@ export interface GitHubSponsorUser {
}
export interface GitHubSponsorsResponse {
- sponsorsActivities: {
- nodes: Array
- }
- sponsors: {
- totalCount: number
- edges: Array<{
- node: GitHubSponsorUser
- }>
- }
+ totalCount: number
+ currentSponsors: GitHubSponsorUser[]
+ pastSponsors: GitHubSponsorUser[]
}
export const getGitHubSponsors = () => {
- const SPONSOR_NODE_QUERY = `
- ... on User {
- login
- name
- url
- avatarUrl
- websiteUrl
- }
- ... on Organization {
- login
- name
- url
- avatarUrl
- websiteUrl
- }
- `
-
- // https://github.com/orgs/community/discussions/37234#discussioncomment-4047906
- // https://github.com/dohooo/get-past-sponsors
- // https://github.com/community/community/discussions/3818#discussioncomment-2155340
- // https://docs.github.com/en/graphql/reference/objects#sponsorsactivity
- // https://docs.github.com/en/graphql/reference/enums#sponsorsactivityaction
- return graphqlGitHub(`
- sponsorsActivities(first:100, period: ALL, orderBy: { direction: DESC, field: TIMESTAMP }, actions: [NEW_SPONSORSHIP, CANCELLED_SPONSORSHIP]) {
- nodes {
- action,
- sponsorsTier {
- isOneTime
- },
- sponsor {
- ${SPONSOR_NODE_QUERY}
- }
- }
- },
- sponsors(first: 100) {
- totalCount
- edges {
- node {
- ${SPONSOR_NODE_QUERY}
- }
- }
- }
- `)
+ return fetchGitHubStatisticJSON('github.sponsors.json')
}
-const isISODateString = (dateString: string) => {
- if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(dateString)) return false
- return new Date(dateString).toISOString() === dateString
+export interface GitHubContributionDay {
+ weekday: number
+ date: string // YYYY-MM-DD
+ contributionCount: number
+ color: string
}
-export const getGitHubContributions = async (from: string, to: string): Promise => {
- if (!isISODateString(from) || !isISODateString(to)) {
- return Promise.reject('Invalid date string!')
- }
-
- const result = await graphqlGitHub(`
- contributionsCollection(from: "${from}", to: "${to}") {
- contributionCalendar {
- totalContributions
- weeks {
- contributionDays {
- weekday
- date
- contributionCount
- color
- }
- }
- }
- }
- `)
+export interface GitHubContributionsResponse {
+ totalContributions: number
+ weeks: Array<{
+ contributionDays: Array
+ }>
+}
- return result.contributionsCollection.contributionCalendar
+export const getGitHubContributions = () => {
+ return fetchGitHubStatisticJSON('github.contributions.json')
}
diff --git a/src/server/getters/npm.ts b/src/server/getters/npm.ts
new file mode 100644
index 00000000..f2312372
--- /dev/null
+++ b/src/server/getters/npm.ts
@@ -0,0 +1,39 @@
+/**
+ * @file BFF NPM getter
+ * @module server.getter.npm
+ * @author Surmon
+ */
+
+import { fetchGitHubStatisticJSON } from './github'
+
+export interface NpmStatistic {
+ totalPackages: number
+ totalDownloads: number
+ averageScore: number
+}
+
+interface NPM_JSON {
+ downloads: Record
+ packages: Array
+}
+
+export const getNPMStatistic = async () => {
+ const data = await fetchGitHubStatisticJSON('npm.json')
+ const totalPackages = data ? Object.keys(data.downloads).length : 0
+ const totalDownloads = data ? Object.values(data.downloads).reduce((p, c) => p + c, 0) : 0
+ const averageScore = (() => {
+ const packages = data?.packages
+ if (!packages?.length) {
+ return 0
+ }
+ // https://itnext.io/increasing-an-npm-packages-search-score-fb557f859300
+ const totalScore = packages.reduce((p, c) => p + c.score.final, 0)
+ return (totalScore / packages.length).toFixed(3)
+ })()
+
+ return {
+ totalPackages,
+ totalDownloads,
+ averageScore
+ } as NpmStatistic
+}
diff --git a/src/server/getters/open-srouce.ts b/src/server/getters/open-srouce.ts
deleted file mode 100644
index 7e04c6a7..00000000
--- a/src/server/getters/open-srouce.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * @file BFF open-srouce getter
- * @module server.getter.open-srouce
- * @author Surmon
- */
-
-import axios from '@/server/services/axios'
-import { IDENTITIES } from '@/config/app.config'
-
-const fetchStatisticJSON = async (fileName: string): Promise => {
- const url = `https://raw.githubusercontent.com/${IDENTITIES.GITHUB_USER_NAME}/${IDENTITIES.GITHUB_USER_NAME}/release/${fileName}`
- const response = await axios.get(url, { timeout: 6000 })
- return response.data
-}
-
-export interface GitHubStatistic {
- followerCount: number
- followingCount: number
- gistCount: number
- repositoryCount: number
- organizationCount: number
- totalStarCount: number
- totalCodeSize: number
-}
-
-export const getGitHubStatistic = () => {
- return fetchStatisticJSON('github.json').then((data) => ({
- followerCount: data.userinfo.followers,
- followingCount: data.userinfo.following,
- gistCount: data.userinfo.public_gists,
- repositoryCount: data.userinfo.public_repos,
- organizationCount: data.organizations.length,
- totalStarCount: data.statistics.stars,
- totalCodeSize: data.statistics.size
- }))
-}
-
-export interface NpmStatistic {
- totalPackages: number
- totalDownloads: number
- averageScore: number
-}
-
-interface NPM_JSON {
- downloads: Record
- packages: Array
-}
-
-export const getNPMStatistic = () => {
- return fetchStatisticJSON('npm.json').then((data) => {
- const totalPackages = data ? Object.keys(data.downloads).length : 0
- const totalDownloads = data ? Object.values(data.downloads).reduce((p, c) => p + c, 0) : 0
- const averageScore = (() => {
- const packages = data?.packages
- if (!packages?.length) {
- return 0
- }
- // https://itnext.io/increasing-an-npm-packages-search-score-fb557f859300
- const totalScore = packages.reduce((p, c) => p + c.score.final, 0)
- return (totalScore / packages.length).toFixed(3)
- })()
-
- return {
- totalPackages,
- totalDownloads,
- averageScore
- } as NpmStatistic
- })
-}
diff --git a/src/stores/_hook.ts b/src/stores/_hook.ts
index f4bf96bf..ff76e47d 100755
--- a/src/stores/_hook.ts
+++ b/src/stores/_hook.ts
@@ -13,7 +13,7 @@ import { useCategoryStore } from './category'
import { useTagStore } from './tag'
import { useIdentityStore } from './identity'
import { useWallpaperStore } from './wallpaper'
-import { useSponsorStore } from './sponsor'
+import { useGitHubSponsorsStore } from './sponsors'
import { useAdminInfoStore, useAppOptionStore } from './basic'
import { useNodepressStatisticStore, useGitHubStatisticStore, useNpmStatisticStore } from './statistic'
import { useArticleCalendarStore, useInstagramCalendarStore, useGitHubCalendarStore } from './calendar'
@@ -38,6 +38,7 @@ export const useStores = (pinia?: Pinia) => ({
featuredArticleList: useFeaturedArticleListStore(pinia),
latestArticleList: useLatestArticleListStore(pinia),
+ // BIZ
articleList: useArticleListStore(pinia),
articleDetail: useArticleDetailStore(pinia),
announcement: useAnnouncementStore(pinia),
@@ -49,16 +50,21 @@ export const useStores = (pinia?: Pinia) => ({
adminInfo: useAdminInfoStore(pinia),
appOption: useAppOptionStore(pinia),
wallpaper: useWallpaperStore(pinia),
- sponsor: useSponsorStore(pinia),
+ // sponsor
+ githubSponsors: useGitHubSponsorsStore(pinia),
+
+ // statistic
nodepressStatistic: useNodepressStatisticStore(pinia),
githubStatistic: useGitHubStatisticStore(pinia),
npmStatistic: useNpmStatisticStore(pinia),
+ // calendar
articleCalendar: useArticleCalendarStore(pinia),
instagramCalendar: useInstagramCalendarStore(pinia),
githubCalendar: useGitHubCalendarStore(pinia),
+ // third
doubanMovies: useDoubanMoviesStore(pinia),
twitterProfile: useTwitterProfileStore(pinia),
twitterLatestTweets: useTwitterLatestTweetsStore(pinia),
diff --git a/src/stores/calendar.ts b/src/stores/calendar.ts
index 0c129be7..998b0062 100755
--- a/src/stores/calendar.ts
+++ b/src/stores/calendar.ts
@@ -8,6 +8,7 @@ import { computed } from 'vue'
import { defineStore } from 'pinia'
import { createFetchStore } from './_fetch'
import { TunnelModule } from '/@/constants/tunnel'
+import type { GitHubContributionsResponse } from '/@/server/getters/github'
import nodepress from '/@/services/nodepress'
import tunnel from '/@/services/tunnel'
@@ -40,7 +41,7 @@ export const useGitHubCalendarStore = defineStore('githubContributionsCalendar',
const fetchStore = createFetchStore({
once: true,
data: null,
- fetcher: () => tunnel.dispatch(TunnelModule.GitHubContributions)
+ fetcher: () => tunnel.dispatch(TunnelModule.GitHubContributions)
})
const days = computed>(() => {
diff --git a/src/stores/sponsor.ts b/src/stores/sponsor.ts
deleted file mode 100644
index c32ff592..00000000
--- a/src/stores/sponsor.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * @file Sponsor state
- * @module store.sponsor
- * @author Surmon
- */
-
-import { computed } from 'vue'
-import { defineStore } from 'pinia'
-import { createFetchStore } from './_fetch'
-import type { GitHubSponsorsResponse, GitHubSponsorUser } from '/@/server/getters/github'
-import { TunnelModule } from '/@/constants/tunnel'
-import tunnel from '/@/services/tunnel'
-
-export const useSponsorStore = defineStore('githubSponsor', () => {
- const fetchStore = createFetchStore({
- fetcher: () => tunnel.dispatch(TunnelModule.GitHubSponsors),
- once: true,
- data: null
- })
-
- const activeSponsors = computed(() => {
- return fetchStore.data.value?.sponsors.edges.map((edge) => edge.node) || []
- })
-
- const inactiveSponsors = computed(() => {
- // 1. order by TIMESTAMP/DESC
- // 2. filter out current sponsors
- // 3. the latest user to cancel is at the head of the array
- // 4. no cancellation events for one-time sponsor
- const result: GitHubSponsorUser[] = []
- const activeSponsorLogins = activeSponsors.value.map((item) => item.login)
- fetchStore.data.value?.sponsorsActivities.nodes.forEach((node) => {
- // Recently, GitHub returned the Ghost user as null
- if (node && node.sponsor.login !== 'ghost') {
- if (node.action === 'CANCELLED_SPONSORSHIP' || node.sponsorsTier.isOneTime) {
- if (!activeSponsorLogins.includes(node.sponsor.login)) {
- result.push(node.sponsor)
- }
- }
- }
- })
- return result
- })
-
- return {
- ...fetchStore,
- activeSponsors,
- inactiveSponsors
- }
-})
diff --git a/src/stores/sponsors.ts b/src/stores/sponsors.ts
new file mode 100644
index 00000000..797694e2
--- /dev/null
+++ b/src/stores/sponsors.ts
@@ -0,0 +1,19 @@
+/**
+ * @file Sponsors state
+ * @module store.sponsors
+ * @author Surmon
+ */
+
+import { defineStore } from 'pinia'
+import { createFetchStore } from './_fetch'
+import type { GitHubSponsorsResponse } from '/@/server/getters/github'
+import { TunnelModule } from '/@/constants/tunnel'
+import tunnel from '/@/services/tunnel'
+
+export const useGitHubSponsorsStore = defineStore('githubSponsors', () => {
+ return createFetchStore({
+ fetcher: () => tunnel.dispatch(TunnelModule.GitHubSponsors),
+ once: true,
+ data: null
+ })
+})
diff --git a/src/stores/statistic.ts b/src/stores/statistic.ts
index 2af131d2..3da33597 100755
--- a/src/stores/statistic.ts
+++ b/src/stores/statistic.ts
@@ -7,7 +7,8 @@
import { defineStore } from 'pinia'
import { createFetchStore } from './_fetch'
import { TunnelModule } from '/@/constants/tunnel'
-import type { GitHubStatistic, NpmStatistic } from '/@/server/getters/open-srouce'
+import type { NpmStatistic } from '/@/server/getters/npm'
+import type { GitHubStatistic } from '/@/server/getters/github'
import nodepress from '/@/services/nodepress'
import tunnel from '/@/services/tunnel'
@@ -35,7 +36,7 @@ export const useGitHubStatisticStore = defineStore('githubStatistic', () => {
return createFetchStore({
once: true,
data: null,
- fetcher: () => tunnel.dispatch(TunnelModule.OpenSourceGitHubStatistic)
+ fetcher: () => tunnel.dispatch(TunnelModule.StatisticGitHubJson)
})
})
@@ -43,6 +44,6 @@ export const useNpmStatisticStore = defineStore('npmStatistic', () => {
return createFetchStore({
once: true,
data: null,
- fetcher: () => tunnel.dispatch(TunnelModule.OpenSourceNPMStatistic)
+ fetcher: () => tunnel.dispatch(TunnelModule.StatisticNpmJson)
})
})