File size: 4,951 Bytes
f16770d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a89840b
84687c0
 
 
 
796f40d
 
 
f16770d
84687c0
 
 
 
796f40d
84687c0
 
 
 
 
 
f16770d
84687c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f16770d
 
84687c0
f16770d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd81592
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const GITHUB_BASE_URL =
  "https://raw.githubusercontent.com/preview4r/AstroLens-Horoscope-Data-Storage/main";

const getCurrentDate = () => {
  const today = new Date();
  return today.toISOString().split("T")[0];
};

const decodeBase64UTF8 = (base64String) => {
  try {
    const binaryString = atob(base64String);

    const bytes = new Uint8Array(binaryString.length);
    for (let i = 0; i < binaryString.length; i++) {
      bytes[i] = binaryString.charCodeAt(i);
    }

    const decoder = new TextDecoder("utf-8");
    return decoder.decode(bytes);
  } catch (error) {
    console.error("Error decoding base64 UTF-8:", error);
    return null;
  }
};

export const fetchHoroscopeData = async (category, period) => {
  try {
    const currentDate = getCurrentDate();
    const fileName = `${category}_${period}.json`;
    const url = `https://api.github.com/repos/preview4r/AstroLens-Horoscope-Data-Storage/contents/data/${currentDate}/${fileName}`;

    const headers = {
      Accept: "application/vnd.github.v3+json",
    };
    
    if (window?.huggingface?.variables?.REACT_APP_GITHUB_TOKEN) {
      headers["Authorization"] = `token ${window?.huggingface?.variables?.REACT_APP_GITHUB_TOKEN}`;
    }

    console.log("Fetching from URL:", url);
    console.log(
      "Using token:",
      window?.huggingface?.variables?.REACT_APP_GITHUB_TOKEN ? "Yes" : "No"
    );

    const response = await fetch(url, { headers });

    console.log("Response status:", response.status);

    if (!response.ok) {
      throw new Error(
        `GitHub API error: ${response.status} - ${response.statusText}`
      );
    }

    const githubResponse = await response.json();

    if (githubResponse.content) {
      const cleanBase64 = githubResponse.content.replace(/\n/g, "");

      const decodedContent = decodeBase64UTF8(cleanBase64);

      if (!decodedContent) {
        throw new Error("Failed to decode base64 content");
      }

      const data = JSON.parse(decodedContent);
      console.log("Successfully loaded data:", data);
      return data;
    } else {
      throw new Error("No content in GitHub response");
    }
  } catch (error) {
    console.error("Error fetching horoscope data:", error);
    return null;
  }
};

export const fallbackHoroscopeContent = {
  overall: {
    today:
      "Today brings a harmonious blend of opportunities and challenges across all aspects of your life. Your natural instincts will guide you well.",
    week: "This week promises balanced growth in multiple areas. Trust your intuition as you navigate new experiences.",
    month:
      "A month of significant personal development awaits. Embrace change and new perspectives with confidence.",
    year: "This year marks a transformative period of growth, bringing profound insights and meaningful achievements.",
  },
  love: {
    today:
      "Love is in the air today! Your romantic side is highlighted, making it a perfect day for expressing your feelings.",
    week: "This week brings romantic opportunities and deepening connections with your loved ones.",
    month:
      "A month of passionate encounters and meaningful relationships awaits you.",
    year: "This year will be transformative for your love life, bringing lasting happiness.",
  },
  health: {
    today:
      "Your energy levels are high today. Focus on maintaining balance between work and rest.",
    week: "Pay attention to your physical wellbeing this week. Small changes can make big differences.",
    month:
      "This month emphasizes the importance of mental and physical health harmony.",
    year: "A year of wellness and vitality lies ahead. Make health your priority.",
  },
  relationship: {
    today:
      "Relationships flourish under today's cosmic energy. Communication is key to success.",
    week: "Strengthen your bonds with family and friends through meaningful conversations.",
    month:
      "Social connections expand this month, bringing new friendships and opportunities.",
    year: "Your social circle will grow significantly, enriching your life in unexpected ways.",
  },
  finance: {
    today:
      "Financial opportunities present themselves today. Stay alert for new possibilities.",
    week: "This week favors careful financial planning and smart investments.",
    month:
      "Money matters require attention this month. Budget wisely for future security.",
    year: "Financial growth and stability are highlighted throughout this year.",
  },
  fortune: {
    today:
      "Lucky energies surround you today. Trust your instincts and take calculated risks for unexpected rewards.",
    week: "Fortune favors the bold this week. Positive surprises and serendipitous encounters await.",
    month:
      "A month of abundance and good fortune unfolds. Opportunities align perfectly with your goals.",
    year: "This year brings remarkable luck and prosperity. Your efforts will be rewarded beyond expectations.",
  },
};