mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-03 20:12:59 +00:00
s
This commit is contained in:
+4
-4
@@ -374,7 +374,7 @@
|
||||
<a href="http://ppc-app/pwkweb2/" class="hover:text-brand-light-blue">Obědy</a>
|
||||
<a href="http://osticket/" class="hover:text-brand-light-blue">OSticket</a>
|
||||
<a href="http://kanboard/" class="hover:text-brand-light-blue">Kanboard</a>
|
||||
<a href="http://webportal/kontakt" class="hover:text-brand-light-blue">Kontakt</a>
|
||||
<a href="http://webportal:8080" class="hover:text-brand-light-blue">Kontakt</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -385,7 +385,7 @@
|
||||
<a href="http://ppc-app/pwkweb2/" class="block px-3 py-2 rounded-md text-base font-medium hover:text-brand-light-blue">Obědy</a>
|
||||
<a href="http://osticket/" class="block px-3 py-2 rounded-md text-base font-medium hover:text-brand-light-blue">OSticket</a>
|
||||
<a href="http://kanboard/" class="block px-3 py-2 rounded-md text-base font-medium hover:text-brand-light-blue">Kanboard</a>
|
||||
<a href="webportal/kontakt" class="block px-3 py-2 rounded-md text-base font-medium hover:text-brand-light-blue">Kontakt</a>
|
||||
<a href="webportal:8080" class="block px-3 py-2 rounded-md text-base font-medium hover:text-brand-light-blue">Kontakt</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -456,7 +456,7 @@
|
||||
<p class="text-xs text-gray-500">Firemní kontakty a důležitá čísla</p>
|
||||
</div>
|
||||
</div>
|
||||
<a href="http://webportal/kontakt" class="text-sm text-blue-600 hover:text-blue-800 hover:underline">
|
||||
<a href="http://webportal:8080" class="text-sm text-blue-600 hover:text-blue-800 hover:underline">
|
||||
Otevřít
|
||||
</a>
|
||||
</div>
|
||||
@@ -484,7 +484,7 @@
|
||||
<li><a href="http://webportal/evidence-aut" class="hover:text-white">Evidence aut</a></li>
|
||||
<li><a href="http://ppc-app/pwkweb2/" class="hover:text-white">Objednávka obědů</a></li>
|
||||
<li><a href="http://osticket/" class="hover:text-white">Technická podpora</a></li>
|
||||
<li><a href="http://webportal/kontakt" class="hover:text-white">Kontakty</a></li>
|
||||
<li><a href="http://webportal:8080" class="hover:text-white">Kontakty</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user