mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 12:32:59 +00:00
dd
This commit is contained in:
@@ -239,368 +239,368 @@ const appsFile = "data/apps.json"
|
|||||||
|
|
||||||
// loadApps loads apps from the JSON file
|
// loadApps loads apps from the JSON file
|
||||||
func loadApps() ([]App, error) {
|
func loadApps() ([]App, error) {
|
||||||
var apps []App
|
var apps []App
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if _, err := os.Stat(appsFile); os.IsNotExist(err) {
|
if _, err := os.Stat(appsFile); os.IsNotExist(err) {
|
||||||
// Return empty slice if file doesn't exist
|
// Return empty slice if file doesn't exist
|
||||||
return []App{}, nil
|
return []App{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read file
|
// Read file
|
||||||
data, err := os.ReadFile(appsFile)
|
data, err := os.ReadFile(appsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading apps file: %v", err)
|
return nil, fmt.Errorf("error reading apps file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal JSON
|
// Unmarshal JSON
|
||||||
if err := json.Unmarshal(data, &apps); err != nil {
|
if err := json.Unmarshal(data, &apps); err != nil {
|
||||||
return nil, fmt.Errorf("error parsing apps JSON: %v", err)
|
return nil, fmt.Errorf("error parsing apps JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps, nil
|
return apps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveApps saves apps to the JSON file
|
// saveApps saves apps to the JSON file
|
||||||
func saveApps(apps []App) error {
|
func saveApps(apps []App) error {
|
||||||
// Create data directory if it doesn't exist
|
// Create data directory if it doesn't exist
|
||||||
if err := os.MkdirAll(filepath.Dir(appsFile), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(appsFile), 0755); err != nil {
|
||||||
return fmt.Errorf("error creating data directory: %v", err)
|
return fmt.Errorf("error creating data directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal to pretty-printed JSON
|
// Marshal to pretty-printed JSON
|
||||||
data, err := json.MarshalIndent(apps, "", " ")
|
data, err := json.MarshalIndent(apps, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling apps to JSON: %v", err)
|
return fmt.Errorf("error marshaling apps to JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
if err := os.WriteFile(appsFile, data, 0644); err != nil {
|
if err := os.WriteFile(appsFile, data, 0644); err != nil {
|
||||||
return fmt.Errorf("error writing apps file: %v", err)
|
return fmt.Errorf("error writing apps file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// App Handlers
|
// App Handlers
|
||||||
func GetAppsHandler(w http.ResponseWriter, r *http.Request) {
|
func GetAppsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Set CORS headers
|
// Set CORS headers
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
|
|
||||||
// Handle preflight requests
|
// Handle preflight requests
|
||||||
if r.Method == "OPTIONS" {
|
if r.Method == "OPTIONS" {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow GET requests
|
// Only allow GET requests
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load apps from JSON file
|
// Load apps from JSON file
|
||||||
apps, err := loadApps()
|
apps, err := loadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading apps: %v", err)
|
log.Printf("Error loading apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return empty array if no apps
|
// Return empty array if no apps
|
||||||
if apps == nil {
|
if apps == nil {
|
||||||
apps = []App{}
|
apps = []App{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add hardcoded apps
|
// Add hardcoded apps
|
||||||
hardcodedApps := []App{
|
hardcodedApps := []App{
|
||||||
{
|
{
|
||||||
ID: "hardcoded-car",
|
ID: "hardcoded-car",
|
||||||
Name: "Záznam služebních jízd",
|
Name: "Záznam služebních jízd",
|
||||||
URL: "/evidence-aut",
|
URL: "/evidence-aut",
|
||||||
Description: "Jednoduchý systém pro evidenci a správu jízd služebními vozidly.",
|
Description: "Jednoduchý systém pro evidenci a správu jízd služebními vozidly.",
|
||||||
Icon: "fa-car-side",
|
Icon: "fa-car-side",
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "hardcoded-lunch",
|
ID: "hardcoded-lunch",
|
||||||
Name: "Objednávka obědů",
|
Name: "Objednávka obědů",
|
||||||
URL: "http://ppc-app/pwkweb2/",
|
URL: "http://ppc-app/pwkweb2/",
|
||||||
Description: "Portál pro objednávku a přehled firemních obědů",
|
Description: "Portál pro objednávku a přehled firemních obědů",
|
||||||
Icon: "fa-utensils",
|
Icon: "fa-utensils",
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "hardcoded-osticket",
|
ID: "hardcoded-osticket",
|
||||||
Name: "OSTicket",
|
Name: "OSTicket",
|
||||||
URL: "http://osticket/",
|
URL: "http://osticket/",
|
||||||
Description: "Systém technické podpory a hlášení problémů",
|
Description: "Systém technické podpory a hlášení problémů",
|
||||||
Icon: "fa-headset",
|
Icon: "fa-headset",
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "hardcoded-kanboard",
|
ID: "hardcoded-kanboard",
|
||||||
Name: "Kanboard",
|
Name: "Kanboard",
|
||||||
URL: "http://kanboard/",
|
URL: "http://kanboard/",
|
||||||
Description: "Správa úkolů a projektů v přehledném kanban stylu",
|
Description: "Správa úkolů a projektů v přehledném kanban stylu",
|
||||||
Icon: "fa-tasks",
|
Icon: "fa-tasks",
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine hardcoded and dynamic apps
|
// Combine hardcoded and dynamic apps
|
||||||
allApps := append(hardcodedApps, apps...)
|
allApps := append(hardcodedApps, apps...)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if err := json.NewEncoder(w).Encode(allApps); err != nil {
|
if err := json.NewEncoder(w).Encode(allApps); err != nil {
|
||||||
log.Printf("Error encoding apps to JSON: %v", err)
|
log.Printf("Error encoding apps to JSON: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAppHandler(w http.ResponseWriter, r *http.Request) {
|
func GetAppHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["id"]
|
appID := vars["id"]
|
||||||
|
|
||||||
// Check if it's a hardcoded app
|
// Check if it's a hardcoded app
|
||||||
if strings.HasPrefix(appID, "hardcoded-") {
|
if strings.HasPrefix(appID, "hardcoded-") {
|
||||||
// Return 404 for non-existent hardcoded apps
|
// Return 404 for non-existent hardcoded apps
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load apps from file
|
// Load apps from file
|
||||||
apps, err := loadApps()
|
apps, err := loadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading apps: %v", err)
|
log.Printf("Error loading apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the app by ID
|
// Find the app by ID
|
||||||
var foundApp *App
|
var foundApp *App
|
||||||
for i, app := range apps {
|
for i, app := range apps {
|
||||||
if app.ID == appID {
|
if app.ID == appID {
|
||||||
foundApp = &apps[i]
|
foundApp = &apps[i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if foundApp == nil {
|
if foundApp == nil {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if err := json.NewEncoder(w).Encode(foundApp); err != nil {
|
if err := json.NewEncoder(w).Encode(foundApp); err != nil {
|
||||||
log.Printf("Error encoding app to JSON: %v", err)
|
log.Printf("Error encoding app to JSON: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateAppHandler(w http.ResponseWriter, r *http.Request) {
|
func CreateAppHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Parse form data
|
// Parse form data
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
log.Printf("Error parsing form: %v", err)
|
log.Printf("Error parsing form: %v", err)
|
||||||
http.Error(w, "Error parsing form data", http.StatusBadRequest)
|
http.Error(w, "Error parsing form data", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get form values
|
// Get form values
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
url := r.FormValue("url")
|
url := r.FormValue("url")
|
||||||
description := r.FormValue("description")
|
description := r.FormValue("description")
|
||||||
iconClass := r.FormValue("iconClass")
|
iconClass := r.FormValue("iconClass")
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if name == "" || url == "" || iconClass == "" {
|
if name == "" || url == "" || iconClass == "" {
|
||||||
http.Error(w, "Name, URL, and Icon are required", http.StatusBadRequest)
|
http.Error(w, "Name, URL, and Icon are required", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new app
|
// Create a new app
|
||||||
app := App{
|
app := App{
|
||||||
ID: fmt.Sprintf("app_%d", time.Now().UnixNano()),
|
ID: fmt.Sprintf("app_%d", time.Now().UnixNano()),
|
||||||
Name: strings.TrimSpace(name),
|
Name: strings.TrimSpace(name),
|
||||||
URL: strings.TrimSpace(url),
|
URL: strings.TrimSpace(url),
|
||||||
Description: strings.TrimSpace(description),
|
Description: strings.TrimSpace(description),
|
||||||
IconClass: iconClass,
|
IconClass: iconClass,
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing apps
|
// Load existing apps
|
||||||
apps, err := loadApps()
|
apps, err := loadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading apps: %v", err)
|
log.Printf("Error loading apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new app to the list
|
// Add the new app to the list
|
||||||
apps = append(apps, app)
|
apps = append(apps, app)
|
||||||
|
|
||||||
// Save the updated list of apps
|
// Save the updated list of apps
|
||||||
if err := saveApps(apps); err != nil {
|
if err := saveApps(apps); err != nil {
|
||||||
log.Printf("Error saving apps: %v", err)
|
log.Printf("Error saving apps: %v", err)
|
||||||
// No need to clean up files since we're not handling file uploads anymore
|
// No need to clean up files since we're not handling file uploads anymore
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
if err := json.NewEncoder(w).Encode(app); err != nil {
|
if err := json.NewEncoder(w).Encode(app); err != nil {
|
||||||
log.Printf("Error encoding app to JSON: %v", err)
|
log.Printf("Error encoding app to JSON: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAppHandler(w http.ResponseWriter, r *http.Request) {
|
func UpdateAppHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["id"]
|
appID := vars["id"]
|
||||||
|
|
||||||
// Prevent updating hardcoded apps
|
// Prevent updating hardcoded apps
|
||||||
if strings.HasPrefix(appID, "hardcoded-") {
|
if strings.HasPrefix(appID, "hardcoded-") {
|
||||||
http.Error(w, "Cannot update hardcoded app", http.StatusForbidden)
|
http.Error(w, "Cannot update hardcoded app", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse form data
|
// Parse form data
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
log.Printf("Error parsing form: %v", err)
|
log.Printf("Error parsing form: %v", err)
|
||||||
http.Error(w, "Error parsing form data", http.StatusBadRequest)
|
http.Error(w, "Error parsing form data", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get form values
|
// Get form values
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
url := r.FormValue("url")
|
url := r.FormValue("url")
|
||||||
description := r.FormValue("description")
|
description := r.FormValue("description")
|
||||||
iconClass := r.FormValue("iconClass")
|
iconClass := r.FormValue("iconClass")
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if name == "" || url == "" || iconClass == "" {
|
if name == "" || url == "" || iconClass == "" {
|
||||||
http.Error(w, "Name, URL, and Icon are required", http.StatusBadRequest)
|
http.Error(w, "Name, URL, and Icon are required", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing apps
|
// Load existing apps
|
||||||
apps, err := loadApps()
|
apps, err := loadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading apps: %v", err)
|
log.Printf("Error loading apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the app to update
|
// Find the app to update
|
||||||
var found bool
|
var found bool
|
||||||
var updatedApps []App
|
var updatedApps []App
|
||||||
for _, app := range apps {
|
for _, app := range apps {
|
||||||
if app.ID == appID {
|
if app.ID == appID {
|
||||||
// Update the app
|
// Update the app
|
||||||
app.Name = strings.TrimSpace(name)
|
app.Name = strings.TrimSpace(name)
|
||||||
app.URL = strings.TrimSpace(url)
|
app.URL = strings.TrimSpace(url)
|
||||||
app.Description = strings.TrimSpace(description)
|
app.Description = strings.TrimSpace(description)
|
||||||
app.IconClass = iconClass
|
app.IconClass = iconClass
|
||||||
app.UpdatedAt = time.Now().Format(time.RFC3339)
|
app.UpdatedAt = time.Now().Format(time.RFC3339)
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
updatedApps = append(updatedApps, app)
|
updatedApps = append(updatedApps, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
http.Error(w, "App not found", http.StatusNotFound)
|
http.Error(w, "App not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the updated apps
|
// Save the updated apps
|
||||||
if err := saveApps(updatedApps); err != nil {
|
if err := saveApps(updatedApps); err != nil {
|
||||||
log.Printf("Error saving apps: %v", err)
|
log.Printf("Error saving apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if err := json.NewEncoder(w).Encode(updatedApps); err != nil {
|
if err := json.NewEncoder(w).Encode(updatedApps); err != nil {
|
||||||
log.Printf("Error encoding apps to JSON: %v", err)
|
log.Printf("Error encoding apps to JSON: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteAppHandler(w http.ResponseWriter, r *http.Request) {
|
func DeleteAppHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["id"]
|
appID := vars["id"]
|
||||||
|
|
||||||
// Prevent deleting hardcoded apps
|
// Prevent deleting hardcoded apps
|
||||||
if strings.HasPrefix(appID, "hardcoded-") {
|
if strings.HasPrefix(appID, "hardcoded-") {
|
||||||
http.Error(w, "Cannot delete hardcoded app", http.StatusForbidden)
|
http.Error(w, "Cannot delete hardcoded app", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing apps
|
// Load existing apps
|
||||||
apps, err := loadApps()
|
apps, err := loadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading apps: %v", err)
|
log.Printf("Error loading apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the app to delete
|
// Find the app to delete
|
||||||
var appIndex = -1
|
var appIndex = -1
|
||||||
var iconToDelete string
|
var iconToDelete string
|
||||||
for i, app := range apps {
|
for i, app := range apps {
|
||||||
if app.ID == appID {
|
if app.ID == appID {
|
||||||
appIndex = i
|
appIndex = i
|
||||||
iconToDelete = app.Icon
|
iconToDelete = app.Icon
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if appIndex == -1 {
|
if appIndex == -1 {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the app from the slice
|
// Remove the app from the slice
|
||||||
updatedApps := append(apps[:appIndex], apps[appIndex+1:]...)
|
updatedApps := append(apps[:appIndex], apps[appIndex+1:]...)
|
||||||
|
|
||||||
// Save the updated apps
|
// Save the updated apps
|
||||||
if err := saveApps(updatedApps); err != nil {
|
if err := saveApps(updatedApps); err != nil {
|
||||||
log.Printf("Error saving apps: %v", err)
|
log.Printf("Error saving apps: %v", err)
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the app had an icon, check if it's used by any other app before deleting
|
// If the app had an icon, check if it's used by any other app before deleting
|
||||||
if iconToDelete != "" {
|
if iconToDelete != "" {
|
||||||
// Check if any other app is using this icon
|
// Check if any other app is using this icon
|
||||||
iconInUse := false
|
iconInUse := false
|
||||||
for _, app := range updatedApps {
|
for _, app := range updatedApps {
|
||||||
if app.Icon == iconToDelete {
|
if app.Icon == iconToDelete {
|
||||||
iconInUse = true
|
iconInUse = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the icon file if it's not in use
|
// Delete the icon file if it's not in use
|
||||||
if !iconInUse {
|
if !iconInUse {
|
||||||
iconPath := filepath.Join("uploads", iconToDelete)
|
iconPath := filepath.Join("uploads", iconToDelete)
|
||||||
if _, err := os.Stat(iconPath); err == nil {
|
if _, err := os.Stat(iconPath); err == nil {
|
||||||
if err := os.Remove(iconPath); err != nil {
|
if err := os.Remove(iconPath); err != nil {
|
||||||
log.Printf("Error deleting icon file: %v", err)
|
log.Printf("Error deleting icon file: %v", err)
|
||||||
// Continue even if we can't delete the file
|
// Continue even if we can't delete the file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -681,11 +681,11 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error {
|
func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error {
|
||||||
smtpHost := "mail.pp-kunovice.cz"
|
smtpHost := "smtp.gmail.com"
|
||||||
smtpPort := 465
|
smtpPort := 465
|
||||||
sender := "sluzebnicek@pp-kunovice.cz"
|
sender := "contact.dvorak@gmail.com"
|
||||||
password := "7g}qznB5bj"
|
password := "mbos uxwh dhlo ezrj"
|
||||||
recipient := "sluzebnicek@pp-kunovice.cz"
|
recipient := "contact.dvorak@gmail.com"
|
||||||
|
|
||||||
m := gomail.NewMessage()
|
m := gomail.NewMessage()
|
||||||
m.SetHeader("From", sender)
|
m.SetHeader("From", sender)
|
||||||
|
|||||||
Reference in New Issue
Block a user