mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-12-16 12:36:10 +05:00
Add support/list endpoint with fallback data
This commit is contained in:
@@ -25,32 +25,62 @@ func NewSupportHandler() *SupportHandler {
|
|||||||
return &SupportHandler{}
|
return &SupportHandler{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default supporters data (used as fallback on Vercel)
|
||||||
|
var defaultSupporters = []Supporter{
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
Name: "Sophron Ragozin",
|
||||||
|
Type: "service",
|
||||||
|
Description: "Покупка и продления основного домена neomovies.ru",
|
||||||
|
Contributions: []string{
|
||||||
|
"Домен neomovies.ru",
|
||||||
|
},
|
||||||
|
Year: 2025,
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 2,
|
||||||
|
Name: "Chernuha",
|
||||||
|
Type: "service",
|
||||||
|
Description: "Покупка домена neomovies.run",
|
||||||
|
Contributions: []string{
|
||||||
|
"Домен neomovies.run",
|
||||||
|
},
|
||||||
|
Year: 2025,
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 3,
|
||||||
|
Name: "Iwnuply",
|
||||||
|
Type: "code",
|
||||||
|
Description: "Создание докер контейнера для API и Frontend",
|
||||||
|
Contributions: []string{
|
||||||
|
"Docker",
|
||||||
|
},
|
||||||
|
Year: 2025,
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func (h *SupportHandler) GetSupportersList(w http.ResponseWriter, r *http.Request) {
|
func (h *SupportHandler) GetSupportersList(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// Get the path to supporters-list.json
|
// Try to read from file first
|
||||||
// It should be in the root of the project
|
|
||||||
supportersPath := filepath.Join(".", "supporters-list.json")
|
supportersPath := filepath.Join(".", "supporters-list.json")
|
||||||
|
|
||||||
// Try to read the file
|
|
||||||
data, err := os.ReadFile(supportersPath)
|
data, err := os.ReadFile(supportersPath)
|
||||||
|
|
||||||
|
// If file not found or error reading, use default data
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If file not found, return empty list
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode([]Supporter{})
|
json.NewEncoder(w).Encode(defaultSupporters)
|
||||||
return
|
|
||||||
}
|
|
||||||
// Other errors
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to read supporters list"})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var supporters []Supporter
|
var supporters []Supporter
|
||||||
if err := json.Unmarshal(data, &supporters); err != nil {
|
if err := json.Unmarshal(data, &supporters); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
// If parsing fails, use default data
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to parse supporters list"})
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode(defaultSupporters)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user