11import { useQuery } from '@tanstack/react-query'
2- import { $fetch as publicFetch } from 'ofetch'
32
43type 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-
4528export 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