diff --git a/.vscode/launch.json b/.vscode/launch.json index 965b015..2639c8e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "mode": "auto", "program": "${fileDirname}" - ,"env": {"msiinfo":"/usr/bin/msiinfo", "exiftool":"/usr/bin/exiftool"} + ,"env": {"msiinfo":"/usr/bin/msiinfo", "exiftool":"/usr/bin/exiftool","uri":"https://winget.cc.huji.ac.il/installers/","installationDirectory":"/w/installers"} } ] } \ No newline at end of file diff --git a/main.go b/main.go index 576105c..17426e1 100644 --- a/main.go +++ b/main.go @@ -256,19 +256,45 @@ func uploadFileForServer(sqldb *sql.DB, lang string) http.Handler{ } func upload() http.Handler { return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){ - file, header, _ := req.FormFile("myFile") - req.ParseMultipartForm(10000000<<20) - defer file.Close() - filename := header.Filename - tempFile, _ :=os.CreateTemp("Data",header.Filename) - defer tempFile.Close() - fileBytes,_:=io.ReadAll(file) - tempFile.Write(fileBytes) - fn,_:=os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666) - defer fn.Close() - fn.Write(fileBytes) - slog.Info(fmt.Sprint(getDataFromFile("Data/"+filename))) -})} + file, header, err := req.FormFile("myFile") + if err != nil { + http.Error(res, "Failed to read file", http.StatusBadRequest) + return + } + defer file.Close() + req.ParseMultipartForm(10000000<<20) + filename := header.Filename + tempFile, err := os.CreateTemp("Data", header.Filename) + if err != nil { + http.Error(res, "Failed to create temp file", http.StatusInternalServerError) + return + } + defer tempFile.Close() + fileBytes, err := io.ReadAll(file) + if err != nil { + http.Error(res, "Failed to read file bytes", http.StatusInternalServerError) + return + } + _, err = tempFile.Write(fileBytes) + if err != nil { + http.Error(res, "Failed to write to temp file", http.StatusInternalServerError) + return + } + fn, err := os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666) + if err != nil { + http.Error(res, "Failed to open file", http.StatusInternalServerError) + return + } + defer fn.Close() + _, err = fn.Write(fileBytes) + if err != nil { + http.Error(res, "Failed to write to file", http.StatusInternalServerError) + return + } + slog.Info(fmt.Sprint(getDataFromFile("Data/" + filename))) + }) +} + // index creates an HTTP handler that serves the main page with data from the database. // sqldb: The database connection object. diff --git a/packages.go b/packages.go index ead48e9..6469c70 100644 --- a/packages.go +++ b/packages.go @@ -148,7 +148,8 @@ func getVendor(data map[string]string) string { case "Company Name": return strings.ToLower(strings.Replace(val," ","",-1)) - + case "Manufacturer": + return strings.ToLower(strings.Replace(val," ","",-1)) case "Publisher": return strings.ToLower(strings.Replace(val," ","",-1)) @@ -164,7 +165,8 @@ func getProgram(data map[string]string) string { case "Product Name": return strings.ToLower(strings.Replace(val," ","",-1)) - + case "ProductName": + return strings.ToLower(strings.Replace(val," ","",-1)) case "Subject": return strings.ToLower(strings.Replace(val," ","",-1)) } diff --git a/public/script.js b/public/script.js index 8831258..0fa94f0 100644 --- a/public/script.js +++ b/public/script.js @@ -124,18 +124,11 @@ function showContainer(className){ function runme(data){ alert(data) } -async function fetchContent(uri) { - try { - const response = await fetch(uri); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - const content = await response.text(); - return content; - } catch (error) { - console.error(`There was a problem with the fetch operation: ${error.message}`); - } -} +function fetchContent(uri) { + return fetch(uri) + .then(response => response.json()) + .catch(error => console.error('Error:', error)); + } function updateForm(uri, eid){ fetchContent(uri).then(content => { switch(eid){