Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-21 12:49:01 +02:00
committed by GitHub
parent d6d0abc55f
commit c31e86ed0c
2 changed files with 14 additions and 53 deletions
+13 -13
View File
@@ -185,20 +185,20 @@
}); });
}); });
// Function to open Windows Explorer with a specific path using our integrated Go server // Function to open Windows Explorer with a specific path
function openWindowsFolder(path) { function openWindowsFolder(path) {
// Call our Go server to open the folder in Windows Explorer // Using ActiveX to open Windows Explorer (works in IE)
fetch(`/open?path=${encodeURIComponent(path)}`) try {
.then(response => { const shell = new ActiveXObject("Shell.Application");
if (!response.ok) { shell.Explore(path);
throw new Error('Failed to open folder'); return;
} } catch (e) {
console.log('Folder opened successfully'); console.log("ActiveX not supported or disabled");
}) }
.catch(error => {
console.error('Error opening folder:', error); // Fallback to file:// protocol
alert('Could not open folder. Make sure the server is running.'); const encodedPath = path.split('\\').map(part => encodeURIComponent(part)).join('/');
}); window.open('file:///' + encodedPath, '_blank');
} }
</script> </script>
</body> </body>
+1 -40
View File
@@ -8,7 +8,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@@ -51,15 +50,12 @@ func main() {
http.ServeFile(w, r, "evidence-aut.html") http.ServeFile(w, r, "evidence-aut.html")
})) }))
// Add folder opener endpoint
http.HandleFunc("/open", enableCORS(openFolderHandler))
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port == "" { if port == "" {
port = "8080" port = "8080"
} }
log.Printf("Server běží na portu %s (včetně otevírání složek Windows)", port) log.Printf("Server běží na portu %s", port)
err := http.ListenAndServe(":"+port, nil) err := http.ListenAndServe(":"+port, nil)
if err != nil { if err != nil {
log.Fatalf("Chyba při spuštění serveru: %v", err) log.Fatalf("Chyba při spuštění serveru: %v", err)
@@ -160,41 +156,6 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"message":"Záznam byl úspěšně uložen a email odeslán"}`)) w.Write([]byte(`{"message":"Záznam byl úspěšně uložen a email odeslán"}`))
} }
// Handler pro otevírání Windows složek přímo z prohlížeče
func openFolderHandler(w http.ResponseWriter, r *http.Request) {
// 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
log.Printf("Otevírání složky: %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 to clean the path and retry
cleanPath := strings.ReplaceAll(folderPath, "/", "\\")
cmd = exec.Command("explorer.exe", cleanPath)
err = cmd.Start()
if err != nil {
log.Printf("Chyba při otevírání složky: %v", err)
http.Error(w, fmt.Sprintf("Error opening folder: %v", err), http.StatusInternalServerError)
return
}
}
// Return success response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success", "message": fmt.Sprintf("Opening folder: %s", folderPath)})
}
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 := "mail.pp-kunovice.cz"
smtpPort := 465 smtpPort := 465