added debugging
This commit is contained in:
parent
0ce5467340
commit
34f4dfb1fc
7 changed files with 20 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
debug = true
|
||||||
[web]
|
[web]
|
||||||
cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
|
cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
|
||||||
host = '127.0.0.1'
|
host = '127.0.0.1'
|
||||||
|
@ -19,3 +20,4 @@ path = "./storage/files/"
|
||||||
[processing]
|
[processing]
|
||||||
maxparallel = 5
|
maxparallel = 5
|
||||||
oleurl = "http://localhost:5000"
|
oleurl = "http://localhost:5000"
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ func setDefaults() {
|
||||||
viper.SetDefault("db.debug", false)
|
viper.SetDefault("db.debug", false)
|
||||||
viper.SetDefault("processing.oleurl", "http://localhost:5000")
|
viper.SetDefault("processing.oleurl", "http://localhost:5000")
|
||||||
viper.SetDefault("store.path", "./storage/files/")
|
viper.SetDefault("store.path", "./storage/files/")
|
||||||
|
viper.SetDefault("debug", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveConfig() error {
|
func SaveConfig() error {
|
||||||
|
|
|
@ -27,6 +27,6 @@ func Logging(next http.Handler) http.Handler {
|
||||||
|
|
||||||
next.ServeHTTP(wrapped, r)
|
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))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ func MraptorScan(fileID pgtype.UUID) error {
|
||||||
if json.Valid(body) == false {
|
if json.Valid(body) == false {
|
||||||
return fmt.Errorf("JSON not valid")
|
return fmt.Errorf("JSON not valid")
|
||||||
}
|
}
|
||||||
|
slog.Debug("MraptorScan", "file-uuid", fileID.String(), "data", body)
|
||||||
database.InsertJsonResult(fileID, body, "msoffice_mraptor")
|
database.InsertJsonResult(fileID, body, "msoffice_mraptor")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ func OleVBAScan(fileID pgtype.UUID) error {
|
||||||
if json.Valid(body) == false {
|
if json.Valid(body) == false {
|
||||||
return fmt.Errorf("JSON not valid")
|
return fmt.Errorf("JSON not valid")
|
||||||
}
|
}
|
||||||
|
slog.Debug("OleVBAScan", "file-uuid", fileID.String(), "data", body)
|
||||||
database.InsertJsonResult(fileID, body, "msoffice_olevba")
|
database.InsertJsonResult(fileID, body, "msoffice_olevba")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,10 @@ func main() {
|
||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||||
config.ReadConfigFile("")
|
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
|
var wg sync.WaitGroup
|
||||||
database.Connect()
|
database.Connect()
|
||||||
database.Ping()
|
database.Ping()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.jmbit.de/jmb/scanfile/server/internal/database"
|
"git.jmbit.de/jmb/scanfile/server/internal/database"
|
||||||
|
"git.jmbit.de/jmb/scanfile/server/internal/processing"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,12 +31,14 @@ func IndexUploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSize)
|
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSize)
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
fileData, fileHeader, err := r.FormFile("file")
|
fileData, fileHeader, err := r.FormFile("file")
|
||||||
|
slog.Debug("File form submitted", "file-name", fileHeader.Filename, "file-size", fileHeader.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error parsing form in IndexUploadHandler", "error", err)
|
slog.Error("Error parsing form in IndexUploadHandler", "error", err)
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fileBytes, err := io.ReadAll(fileData)
|
fileBytes, err := io.ReadAll(fileData)
|
||||||
|
slog.Debug("File from form read", "file-name", fileHeader.Filename, "file-size", len(fileBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error reading file in IndexUploadHandler", "error", err)
|
slog.Error("Error reading file in IndexUploadHandler", "error", err)
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
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)
|
file, err := database.CreateFile(r.Context(), fileHeader.Filename, fileBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error saving file in IndexUploadHandler", "error", err)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue