ntphuc149 commited on
Commit
db78387
·
verified ·
1 Parent(s): bd81592

Update src/services/horoscopeService.js

Browse files
Files changed (1) hide show
  1. src/services/horoscopeService.js +32 -41
src/services/horoscopeService.js CHANGED
@@ -23,55 +23,46 @@ const decodeBase64UTF8 = (base64String) => {
23
  }
24
  };
25
 
 
26
  export const fetchHoroscopeData = async (category, period) => {
27
  try {
28
  const currentDate = getCurrentDate();
29
  const fileName = `${category}_${period}.json`;
30
- const url = `https://api.github.com/repos/preview4r/AstroLens-Horoscope-Data-Storage/contents/data/${currentDate}/${fileName}`;
31
-
32
- const headers = {
33
- Accept: "application/vnd.github.v3+json",
34
- };
35
-
36
- if (process.env.REACT_APP_GITHUB_TOKEN) {
37
- headers["Authorization"] = `token ${process.env.REACT_APP_GITHUB_TOKEN}`;
38
  }
39
-
40
- console.log("Fetching from URL:", url);
41
- console.log(
42
- "Using token:",
43
- process.env.REACT_APP_GITHUB_TOKEN ? "Yes" : "No"
44
- );
45
-
46
- const response = await fetch(url, { headers });
47
-
48
- console.log("Response status:", response.status);
49
-
 
 
 
 
 
50
  if (!response.ok) {
51
- throw new Error(
52
- `GitHub API error: ${response.status} - ${response.statusText}`
53
- );
54
- }
55
-
56
- const githubResponse = await response.json();
57
-
58
- if (githubResponse.content) {
59
- const cleanBase64 = githubResponse.content.replace(/\n/g, "");
60
-
61
- const decodedContent = decodeBase64UTF8(cleanBase64);
62
-
63
- if (!decodedContent) {
64
- throw new Error("Failed to decode base64 content");
65
- }
66
-
67
- const data = JSON.parse(decodedContent);
68
- console.log("Successfully loaded data:", data);
69
- return data;
70
- } else {
71
- throw new Error("No content in GitHub response");
72
  }
 
 
 
 
 
73
  } catch (error) {
74
- console.error("Error fetching horoscope data:", error);
75
  return null;
76
  }
77
  };
 
23
  }
24
  };
25
 
26
+ // Thay đổi cách lấy token cho Static Space
27
  export const fetchHoroscopeData = async (category, period) => {
28
  try {
29
  const currentDate = getCurrentDate();
30
  const fileName = `${category}_${period}.json`;
31
+ const rawUrl = `https://raw.githubusercontent.com/preview4r/AstroLens-Horoscope-Data-Storage/main/data/${currentDate}/${fileName}`;
32
+
33
+ const headers = {};
34
+
35
+ const githubToken = window?.huggingface?.variables?.REACT_APP_GITHUB_TOKEN;
36
+
37
+ if (githubToken) {
38
+ headers['Authorization'] = `token ${githubToken}`;
39
  }
40
+
41
+ console.log('=== TOKEN DEBUG FOR STATIC SPACE ===');
42
+ console.log('Huggingface object exists:', !!window.huggingface);
43
+ console.log('Variables object exists:', !!window?.huggingface?.variables);
44
+ console.log('Token exists:', !!githubToken);
45
+ console.log('Token preview:', githubToken ? `${githubToken.substring(0, 8)}...` : 'None');
46
+
47
+ console.log('Fetching from raw URL:', rawUrl);
48
+
49
+ const response = await fetch(rawUrl, {
50
+ headers,
51
+ method: 'GET'
52
+ });
53
+
54
+ console.log('Response status:', response.status);
55
+
56
  if (!response.ok) {
57
+ throw new Error(`Failed to fetch: ${response.status} - ${response.statusText}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
+
60
+ const data = await response.json();
61
+ console.log('Successfully loaded data from raw URL:', data);
62
+ return data;
63
+
64
  } catch (error) {
65
+ console.error('Error fetching horoscope data:', error);
66
  return null;
67
  }
68
  };