update for the javascript
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -10,7 +10,7 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${fileDirname}"
|
"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"}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
44
main.go
44
main.go
@@ -256,19 +256,45 @@ func uploadFileForServer(sqldb *sql.DB, lang string) http.Handler{
|
|||||||
}
|
}
|
||||||
func upload() http.Handler {
|
func upload() http.Handler {
|
||||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){
|
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){
|
||||||
file, header, _ := req.FormFile("myFile")
|
file, header, err := req.FormFile("myFile")
|
||||||
req.ParseMultipartForm(10000000<<20)
|
if err != nil {
|
||||||
|
http.Error(res, "Failed to read file", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
req.ParseMultipartForm(10000000<<20)
|
||||||
filename := header.Filename
|
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()
|
defer tempFile.Close()
|
||||||
fileBytes,_:=io.ReadAll(file)
|
fileBytes, err := io.ReadAll(file)
|
||||||
tempFile.Write(fileBytes)
|
if err != nil {
|
||||||
fn,_:=os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
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()
|
defer fn.Close()
|
||||||
fn.Write(fileBytes)
|
_, err = fn.Write(fileBytes)
|
||||||
slog.Info(fmt.Sprint(getDataFromFile("Data/"+filename)))
|
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.
|
// index creates an HTTP handler that serves the main page with data from the database.
|
||||||
// sqldb: The database connection object.
|
// sqldb: The database connection object.
|
||||||
|
@@ -148,7 +148,8 @@ func getVendor(data map[string]string) string {
|
|||||||
|
|
||||||
case "Company Name":
|
case "Company Name":
|
||||||
return strings.ToLower(strings.Replace(val," ","",-1))
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
|
case "Manufacturer":
|
||||||
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
case "Publisher":
|
case "Publisher":
|
||||||
return strings.ToLower(strings.Replace(val," ","",-1))
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
|
|
||||||
@@ -164,7 +165,8 @@ func getProgram(data map[string]string) string {
|
|||||||
|
|
||||||
case "Product Name":
|
case "Product Name":
|
||||||
return strings.ToLower(strings.Replace(val," ","",-1))
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
|
case "ProductName":
|
||||||
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
case "Subject":
|
case "Subject":
|
||||||
return strings.ToLower(strings.Replace(val," ","",-1))
|
return strings.ToLower(strings.Replace(val," ","",-1))
|
||||||
}
|
}
|
||||||
|
@@ -124,18 +124,11 @@ function showContainer(className){
|
|||||||
function runme(data){
|
function runme(data){
|
||||||
alert(data)
|
alert(data)
|
||||||
}
|
}
|
||||||
async function fetchContent(uri) {
|
function fetchContent(uri) {
|
||||||
try {
|
return fetch(uri)
|
||||||
const response = await fetch(uri);
|
.then(response => response.json())
|
||||||
if (!response.ok) {
|
.catch(error => console.error('Error:', error));
|
||||||
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 updateForm(uri, eid){
|
function updateForm(uri, eid){
|
||||||
fetchContent(uri).then(content => {
|
fetchContent(uri).then(content => {
|
||||||
switch(eid){
|
switch(eid){
|
||||||
|
Reference in New Issue
Block a user