Imp: The file does not need to be copied in disk anymore
File is being proccessed from memory directly. We don't need to tempcopy nor delete it because it's not saved to disk.
This commit is contained in:
parent
ea741c17e2
commit
f7cf197b4e
@ -16,7 +16,6 @@ $ cp env-sample .env
|
||||
DOCKER_ENV=production
|
||||
BASE_URL=https://wrap.sh
|
||||
SERVER_PORT=8080
|
||||
UPLOAD_DIR=uploads
|
||||
TOP_N_COMMANDS=10
|
||||
MASTODON_INSTANCE_FOR_SHARING=mastodon.social
|
||||
```
|
||||
@ -61,7 +60,6 @@ $ go mod tidy
|
||||
├── internal/
|
||||
│ ├── web/ # Web logic (routes, controller...)
|
||||
├── result/ # Place for storing the results
|
||||
├── upload/ # Temporal place for storing the uploads (inmediately removed)
|
||||
├── .env.sample # Sample environment file
|
||||
└── README.md # This file
|
||||
└── Dockerfile # Requirement for the docker container to be built
|
||||
|
@ -1,6 +1,5 @@
|
||||
DOCKER_ENV=production
|
||||
BASE_URL=https://wrap.sh
|
||||
SERVER_PORT=8080
|
||||
UPLOAD_DIR=uploads
|
||||
TOP_N_COMMANDS=10
|
||||
MASTODON_INSTANCE_FOR_SHARING=mastodon.social
|
||||
|
@ -32,35 +32,8 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Save temp file
|
||||
// uploadDir := os.Getenv("UPLOAD_DIR")
|
||||
// if uploadDir == "" {
|
||||
// uploadDir = "uploads"
|
||||
// }
|
||||
// os.MkdirAll(uploadDir, os.ModePerm)
|
||||
// tempFile, err := os.CreateTemp(uploadDir, "history-*.txt")
|
||||
// if err != nil {
|
||||
// http.Error(w, "Error saving file", http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// defer tempFile.Close()
|
||||
|
||||
// _, err = io.Copy(tempFile, file)
|
||||
// if err != nil {
|
||||
// http.Error(w, "Error copying file", http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
commandCounts, categories, pipeRedirectionCounts, commonPatterns := ProcessHistory(file)
|
||||
|
||||
// THE UPLOAD FILE IS INMEDIATELY REMOVED
|
||||
// ONCE THE STATS ARE GENERATED
|
||||
// err = os.Remove(tempFile.Name())
|
||||
// if err != nil {
|
||||
// http.Error(w, "Error deleting temporary file", http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
limit := os.Getenv("TOP_N_COMMANDS")
|
||||
limitInt, err := strconv.Atoi(limit)
|
||||
if err != nil {
|
||||
|
@ -2,8 +2,6 @@ package web
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -22,11 +20,6 @@ func ProcessHistory(file multipart.File) (map[string]int, map[string]int, map[st
|
||||
commonPatterns := make(map[string]int)
|
||||
re := regexp.MustCompile(`\S+\.(log|txt|conf|json)`)
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if _, err := io.Copy(buf, file); err != nil {
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
|
||||
// Reset the file pointer to the beginning (if needed)
|
||||
if seeker, ok := file.(multipart.File); ok {
|
||||
seeker.Seek(0, 0)
|
||||
|
@ -16,10 +16,9 @@
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<p class="mb-8 mt-8"><small>Warning: Be sure to edit it beforehand to remove any passwords
|
||||
or commands that might leak sensitive information. While the file is
|
||||
deleted immediately after being uploaded, double-check it before
|
||||
submitting.</small></p>
|
||||
<p class="mb-6 mt-8"><small>⚠️ <strong>Warning</strong>:⚠️ Be sure to edit it beforehand to remove any passwords
|
||||
or commands that might leak sensitive information.</small><p>
|
||||
<p><small>The file is not uploaded anywhere; it is processed in memory to generate the statistics and is automatically discarded.</small></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -103,7 +103,13 @@ func createBarChart(stats []CommandStat) *charts.Bar {
|
||||
}
|
||||
|
||||
bar.SetXAxis(commands).
|
||||
AddSeries("Freq", generateBarItems(counts))
|
||||
AddSeries("Freq", generateBarItems(counts)).
|
||||
SetSeriesOptions(
|
||||
charts.WithLabelOpts(opts.Label{
|
||||
Color: "white",
|
||||
Position: "top",
|
||||
}),
|
||||
)
|
||||
|
||||
return bar
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user