Skip to content

Commit 6249db6

Browse files
fix: get goals from github repo
1 parent f6a33b1 commit 6249db6

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

dashboard/src/components/common/topbar-ad.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function TopbarAd() {
104104

105105
const loadConfig = async () => {
106106
try {
107-
const githubApiUrl = 'https://api.github.com/repos/pasarguard/ads/contents/config'
107+
const githubApiUrl = 'https://api.github.com/repos/pasarguard/ads/contents/config.json'
108108
const response = await fetch(githubApiUrl, {
109109
cache: 'no-cache',
110110
referrerPolicy: 'no-referrer',

dashboard/src/hooks/use-goal.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useQuery } from '@tanstack/react-query'
2-
import { $fetch as publicFetch } from 'ofetch'
32

43
type GoalType = 'donation' | 'github_stars' | (string & {})
54

@@ -26,32 +25,25 @@ interface GoalsResponse {
2625
cancelled_count: number
2726
}
2827

29-
export function useCurrentGoal() {
30-
return useQuery({
31-
queryKey: ['current-goal'],
32-
queryFn: async () => {
33-
const response = await publicFetch<Goal>('https://donate.pasarguard.org/api/v1/goal/current', {
34-
method: 'GET',
35-
referrerPolicy: 'no-referrer',
36-
credentials: 'omit',
37-
})
38-
return response
39-
},
40-
refetchInterval: 60000, // Refetch every minute
41-
retry: 2,
42-
})
43-
}
44-
4528
export function useAllGoals() {
4629
return useQuery({
4730
queryKey: ['all-goals'],
4831
queryFn: async () => {
49-
const response = await publicFetch<GoalsResponse>('https://donate.pasarguard.org/api/v1/goal/list', {
32+
const response = await fetch('https://api.github.com/repos/pasarguard/ads/contents/goal.json', {
5033
method: 'GET',
5134
referrerPolicy: 'no-referrer',
5235
credentials: 'omit',
5336
})
54-
return response
37+
if (response.ok) {
38+
const apiData = await response.json()
39+
if (apiData.content && apiData.encoding === 'base64') {
40+
const base64Content = apiData.content.replace(/\n/g, '')
41+
const binaryString = atob(base64Content)
42+
const utf8String = decodeURIComponent(Array.from(binaryString, char => '%' + ('00' + char.charCodeAt(0).toString(16)).slice(-2)).join(''))
43+
const data: GoalsResponse = JSON.parse(utf8String)
44+
return data
45+
}
46+
}
5547
},
5648
refetchInterval: 300000, // Refetch every 5 minutes
5749
retry: 2,

0 commit comments

Comments
 (0)