update for the javascript

This commit is contained in:
2024-06-23 12:20:50 +03:00
parent 6844fe42bc
commit fae0a35af9
4 changed files with 49 additions and 28 deletions

2
.vscode/launch.json vendored
View File

@@ -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"}
}
]
}

42
main.go
View File

@@ -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)
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, _ :=os.CreateTemp("Data",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,_:=io.ReadAll(file)
tempFile.Write(fileBytes)
fn,_:=os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
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()
fn.Write(fileBytes)
_, 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.

View File

@@ -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))
}

View File

@@ -124,17 +124,10 @@ 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 => {