diff --git a/index.html b/index.html
index 706f563..9a087ac 100644
--- a/index.html
+++ b/index.html
@@ -374,7 +374,7 @@
Obědy
OSticket
Kanboard
- Kontakt
+ Kontakt
@@ -385,7 +385,7 @@
Obědy
OSticket
Kanboard
- Kontakt
+ Kontakt
@@ -456,7 +456,7 @@
Firemní kontakty a důležitá čísla
-
+
Otevřít
@@ -484,7 +484,7 @@
Evidence aut
Objednávka obědů
Technická podpora
- Kontakty
+ Kontakty
diff --git a/main.go b/main.go
index 9974721..20b8b84 100644
--- a/main.go
+++ b/main.go
@@ -188,56 +188,125 @@ func enableCORS(next http.Handler) http.Handler {
})
}
+// In-memory store for apps (in a real app, use a database)
+var appsStore = make(map[string]App)
+var lastAppID = 0
+
// App Handlers
func GetAppsHandler(w http.ResponseWriter, r *http.Request) {
- // In a real app, this would fetch from a database
- apps := []App{
- {
- ID: "1",
- Name: "Kontakt",
- URL: "/kontakt",
- Description: "Kontaktní formulář",
- Icon: "",
- CreatedAt: time.Now().Format(time.RFC3339),
- UpdatedAt: time.Now().Format(time.RFC3339),
- },
+ // Convert map to slice
+ appsList := make([]App, 0, len(appsStore))
+ for _, app := range appsStore {
+ appsList = append(appsList, app)
+ }
+
+ // If no apps, return empty array instead of null
+ if appsList == nil {
+ appsList = []App{}
}
w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(apps)
+ json.NewEncoder(w).Encode(appsList)
}
func GetAppHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
- // In a real app, this would fetch from a database
- if id != "1" {
+ app, exists := appsStore[id]
+ if !exists {
http.Error(w, "App not found", http.StatusNotFound)
return
}
- app := App{
- ID: id,
- Name: "Kontakt",
- URL: "/kontakt",
- Description: "Kontaktní formulář",
- Icon: "",
- CreatedAt: time.Now().Format(time.RFC3339),
- UpdatedAt: time.Now().Format(time.RFC3339),
- }
-
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(app)
}
+func generateUniqueID() string {
+ lastAppID++
+ return fmt.Sprintf("%d", lastAppID)
+}
+
+func handleFileUpload(r *http.Request, fieldName string) (string, error) {
+ file, handler, err := r.FormFile(fieldName)
+ if err != nil {
+ // No file was uploaded
+ return "", nil
+ }
+ defer file.Close()
+
+ // Create uploads directory if it doesn't exist
+ if err := os.MkdirAll("uploads", 0755); err != nil {
+ return "", fmt.Errorf("failed to create uploads directory: %v", err)
+ }
+
+ // Generate a unique filename
+ ext := filepath.Ext(handler.Filename)
+ filename := fmt.Sprintf("%d%s", time.Now().UnixNano(), ext)
+ filepath := filepath.Join("uploads", filename)
+
+ // Create the file
+ out, err := os.Create(filepath)
+ if err != nil {
+ return "", fmt.Errorf("failed to create file: %v", err)
+ }
+ defer out.Close()
+
+ // Copy the file content
+ _, err = io.Copy(out, file)
+ if err != nil {
+ return "", fmt.Errorf("failed to save file: %v", err)
+ }
+
+ return filename, nil
+}
+
func CreateAppHandler(w http.ResponseWriter, r *http.Request) {
// Parse form data
err := r.ParseMultipartForm(10 << 20) // 10 MB max file size
if err != nil {
- http.Error(w, "Error parsing form data", http.StatusBadRequest)
+ http.Error(w, "Error parsing form data: "+err.Error(), http.StatusBadRequest)
return
}
+
+ // Get form values
+ name := r.FormValue("name")
+ url := r.FormValue("url")
+ description := r.FormValue("description")
+
+ // Validate required fields
+ if name == "" || url == "" {
+ http.Error(w, "Name and URL are required", http.StatusBadRequest)
+ return
+ }
+
+ // Handle file upload
+ icon, err := handleFileUpload(r, "icon")
+ if err != nil {
+ http.Error(w, "Error uploading icon: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ // Create new app
+ now := time.Now().Format(time.RFC3339)
+ app := App{
+ ID: generateUniqueID(),
+ Name: name,
+ URL: url,
+ Description: description,
+ Icon: icon,
+ CreatedAt: now,
+ UpdatedAt: now,
+ }
+
+ // Save to in-memory store
+ appsStore[app.ID] = app
+
+ // Return the created app
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusCreated)
+ json.NewEncoder(w).Encode(app)
// Get form values
name := r.FormValue("name")