From b6ed586a2d899354e78aecffc4860885fde9508e Mon Sep 17 00:00:00 2001 From: sandyx Date: Sun, 24 Nov 2024 11:14:22 -0600 Subject: [PATCH] goroutine --- main.go | 67 +++++++++++++++++++++++++++++++----------------------- styles.css | 13 ++++++----- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/main.go b/main.go index f5278e1..98145ed 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,45 @@ func main() { log.Fatal(err) } + for _, e := range entries { + go func() { + new := e.Name() + newImg := strings.TrimSuffix(new, filepath.Ext(new)) + ".png" + + if filepath.Ext(new) != ".pdf" { + return + } + + dir, _ := filepath.Abs(*directory) + + cmd := exec.Command("./tncmd.sh", filepath.Join(dir, e.Name())) + + fmt.Println(cmd) + + if err := cmd.Run(); err != nil { + log.Println(err) + } else { + fmt.Println("Created thumbnail for: " + new) + http.HandleFunc("/" + newImg, func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "img/png") + + file, err := os.Open(*directory +"/"+ newImg) + if err != nil { + http.Error(w, "File not found.", http.StatusNotFound) + return + } + defer file.Close() + + _, err = io.Copy(w, file) + if err != nil { + http.Error(w, "Error sending file.", http.StatusInternalServerError) + return + } + }) + } + }() + } + for _, e := range entries { new := e.Name() newImg := strings.TrimSuffix(new, filepath.Ext(new)) + ".png" @@ -97,34 +136,6 @@ func main() { continue } - dir, _ := filepath.Abs(*directory) - - cmd := exec.Command("./tncmd.sh", filepath.Join(dir, e.Name())) - - fmt.Println(cmd) - - if err := cmd.Run(); err != nil { - log.Println(err) - } else { - fmt.Println("Created thumbnail for: " + new) - http.HandleFunc("/" + newImg, func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "img/png") - - file, err := os.Open(*directory +"/"+ newImg) - if err != nil { - http.Error(w, "File not found.", http.StatusNotFound) - return - } - defer file.Close() - - _, err = io.Copy(w, file) - if err != nil { - http.Error(w, "Error sending file.", http.StatusInternalServerError) - return - } - }) - } - //if new == "style.css" { continue } http.HandleFunc("/" + url.QueryEscape(new), func(w http.ResponseWriter, r *http.Request) { diff --git a/styles.css b/styles.css index cf4d761..a63b88a 100644 --- a/styles.css +++ b/styles.css @@ -1,19 +1,20 @@ .grid-container { font-family: Arial, sans-serif; - font-size: 4vh; + //font-size: 4vh; //width: 100%; display: grid; - grid-template-columns: repeat(100, 1fr); - grid-auto-rows: minmax(100px, auto); + grid-template-columns: repeat(3, 1fr); + grid-auto-rows: minmax(100%, auto); margin-left: 30%; + margin-right: 30%; } .grid-item { - padding: 10px; + padding: 5px; background: green; - border-radius: 20px; + border-radius: 0px; border: 1px solid white; - text-align: left; + text-align: center; } a {