Spaces:
Running
Running
Update src/services/horoscopeService.js
Browse files- 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
|
| 31 |
-
|
| 32 |
-
const headers = {
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
if (
|
| 37 |
-
headers[
|
| 38 |
}
|
| 39 |
-
|
| 40 |
-
console.log(
|
| 41 |
-
console.log(
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
);
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 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(
|
| 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 |
};
|