added debugging

This commit is contained in:
Johannes Bülow 2025-06-12 11:58:44 +02:00
parent 0ce5467340
commit 34f4dfb1fc
Signed by: jmb
GPG key ID: B56971CF7B8F83A6
7 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,4 @@
debug = true
[web]
cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
host = '127.0.0.1'
@ -19,3 +20,4 @@ path = "./storage/files/"
[processing]
maxparallel = 5
oleurl = "http://localhost:5000"

View file

@ -45,6 +45,7 @@ func setDefaults() {
viper.SetDefault("db.debug", false)
viper.SetDefault("processing.oleurl", "http://localhost:5000")
viper.SetDefault("store.path", "./storage/files/")
viper.SetDefault("debug", false)
}
func SaveConfig() error {

View file

@ -27,6 +27,6 @@ func Logging(next http.Handler) http.Handler {
next.ServeHTTP(wrapped, r)
slog.Info("webserver", "status", wrapped.statusCode, "method", r.Method, "path", r.URL.Path, "duration", time.Since(start))
slog.Info("http", "status", wrapped.statusCode, "method", r.Method, "path", r.URL.Path, "duration", time.Since(start))
})
}

View file

@ -36,6 +36,7 @@ func MraptorScan(fileID pgtype.UUID) error {
if json.Valid(body) == false {
return fmt.Errorf("JSON not valid")
}
slog.Debug("MraptorScan", "file-uuid", fileID.String(), "data", body)
database.InsertJsonResult(fileID, body, "msoffice_mraptor")
return nil
}

View file

@ -35,6 +35,7 @@ func OleVBAScan(fileID pgtype.UUID) error {
if json.Valid(body) == false {
return fmt.Errorf("JSON not valid")
}
slog.Debug("OleVBAScan", "file-uuid", fileID.String(), "data", body)
database.InsertJsonResult(fileID, body, "msoffice_olevba")
return nil
}

View file

@ -34,6 +34,10 @@ func main() {
log.SetOutput(os.Stderr)
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
config.ReadConfigFile("")
if viper.GetBool("debug") {
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug})))
slog.Debug("Debug logging enabled")
}
var wg sync.WaitGroup
database.Connect()
database.Ping()

View file

@ -6,6 +6,7 @@ import (
"net/http"
"git.jmbit.de/jmb/scanfile/server/internal/database"
"git.jmbit.de/jmb/scanfile/server/internal/processing"
"github.com/spf13/viper"
)
@ -30,12 +31,14 @@ func IndexUploadHandler(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSize)
defer r.Body.Close()
fileData, fileHeader, err := r.FormFile("file")
slog.Debug("File form submitted", "file-name", fileHeader.Filename, "file-size", fileHeader.Size)
if err != nil {
slog.Error("Error parsing form in IndexUploadHandler", "error", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fileBytes, err := io.ReadAll(fileData)
slog.Debug("File from form read", "file-name", fileHeader.Filename, "file-size", len(fileBytes))
if err != nil {
slog.Error("Error reading file in IndexUploadHandler", "error", err)
http.Error(w, err.Error(), http.StatusBadRequest)
@ -45,7 +48,13 @@ func IndexUploadHandler(w http.ResponseWriter, r *http.Request) {
file, err := database.CreateFile(r.Context(), fileHeader.Filename, fileBytes)
if err != nil {
slog.Error("Error saving file in IndexUploadHandler", "error", err)
http.Error(w, err.Error(), http.StatusBadRequest)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = processing.Submit(r.Context(), file.ID)
if err != nil {
slog.Error("Error submitting file for processing in IndexUploadHandler", "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}