diff --git a/folderopener/main.go b/folderopener/main.go index 39df026..abfb20a 100644 --- a/folderopener/main.go +++ b/folderopener/main.go @@ -11,7 +11,7 @@ import ( func main() { // Set up HTTP server http.HandleFunc("/open", openFolderHandler) - + // Start server on port 8080 fmt.Println("Folder opener server running on http://localhost:8080") log.Fatal(http.ListenAndServe(":8080", nil)) @@ -22,46 +22,46 @@ func openFolderHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS") w.Header().Set("Access-Control-Allow-Headers", "Content-Type") - + // Handle preflight OPTIONS request if r.Method == "OPTIONS" { w.WriteHeader(http.StatusOK) return } - + // Only allow GET requests if r.Method != "GET" { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } - + // Get the folder path from the query parameter folderPath := r.URL.Query().Get("path") if folderPath == "" { http.Error(w, "Missing path parameter", http.StatusBadRequest) return } - + // Log the request fmt.Printf("Opening folder: %s\n", folderPath) - + // Open the folder in Windows Explorer // The /select flag opens Explorer with the specified folder selected cmd := exec.Command("explorer.exe", folderPath) err := cmd.Start() - + if err != nil { // If there was an error, try to clean the path and retry cleanPath := strings.ReplaceAll(folderPath, "/", "\\") cmd = exec.Command("explorer.exe", cleanPath) err = cmd.Start() - + if err != nil { http.Error(w, fmt.Sprintf("Error opening folder: %v", err), http.StatusInternalServerError) return } } - + // Return success response w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Opening folder: %s", folderPath) diff --git a/index.html b/index.html index f1b1824..e431a3d 100644 --- a/index.html +++ b/index.html @@ -72,7 +72,7 @@
Systém technické podpory a hlášení problémů
- + Otevřít aplikaci @@ -82,9 +82,9 @@Správa úkolů a projektů v přehledném kanban stylu
- + Otevřít aplikaci diff --git a/main.go b/main.go index 4337618..934dc7b 100644 --- a/main.go +++ b/main.go @@ -168,32 +168,18 @@ func openFolderHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Missing path parameter", http.StatusBadRequest) return } - + // Log the request log.Printf("Otevírání složky: %s", folderPath) - - // Properly handle backslashes in Windows paths - // First, replace any forward slashes with backslashes - folderPath = strings.ReplaceAll(folderPath, "/", "\\") - // Fix any double backslashes that might have been created by JavaScript escaping - for strings.Contains(folderPath, "\\\\") { - folderPath = strings.ReplaceAll(folderPath, "\\\\", "\\") - } - - // Log the cleaned path - log.Printf("Upravená cesta: %s", folderPath) - // Open the folder in Windows Explorer cmd := exec.Command("explorer.exe", folderPath) err := cmd.Start() if err != nil { - // If there was an error, try opening the parent directory - log.Printf("Chyba při otevírání složky: %v, zkouším jinou metodu", err) - - // Try using /root,path format which sometimes works better - cmd = exec.Command("explorer.exe", "/root," + folderPath) + // If there was an error, try to clean the path and retry + cleanPath := strings.ReplaceAll(folderPath, "/", "\\") + cmd = exec.Command("explorer.exe", cleanPath) err = cmd.Start() if err != nil { @@ -202,7 +188,7 @@ func openFolderHandler(w http.ResponseWriter, r *http.Request) { return } } - + // Return success response w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) diff --git a/myserver.exe b/myserver.exe new file mode 100644 index 0000000..6509af2 Binary files /dev/null and b/myserver.exe differ