workign on the yamls

This commit is contained in:
2024-06-30 15:36:33 +03:00
parent 9a716d8b54
commit e430bfa01f
9 changed files with 143 additions and 35 deletions

View File

@@ -0,0 +1,13 @@
# Created using wingetcreate 1.5.7.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.5.0.schema.json
{{define "installer"}}
PackageIdentifier: {{.PID}}
PackageVersion: {{.VER}}
InstallerType: {{.TYPE}}
Installers:
- Architecture: x64
InstallerUrl: {{.URL}}
InstallerSha256: {{.HASH}}
ManifestType: installer
ManifestVersion: 1.6.0
{{end}}

View File

@@ -0,0 +1,13 @@
# Created using wingetcreate 1.5.7.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.5.0.schema.json
{{define "locale"}}
PackageIdentifier: {{.PID}}
PackageVersion: {{.VER}}
PackageLocale: en-US
Publisher: {{.PUB}}
PackageName: {{.NAME}}
License: MIT
ShortDescription: {{.NAME}}
ManifestType: defaultLocale
ManifestVersion: 1.6.0
{{end}}

View File

@@ -0,0 +1,9 @@
# Created using wingetcreate 1.5.7.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.5.0.schema.json
{{define "yaml"}}
PackageIdentifier: {{.PID}}
PackageVersion: {{.VER}}
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.6.0
{{end}}

30
fileOrginize.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
"html/template"
"log/slog"
"os"
)
func CreateDirectoryInPackageDir(doc yaml) {
location := doc.LOCATION
slog.Debug("Creating the Directory: ", location)
direrr := os.MkdirAll(location, 0764)
if direrr != nil {
slog.Error(direrr.Error())
}
}
func CreateYaml(doc yaml) {
template, err := template.ParseFiles("YamlTemplates/template.yaml")
yamlFile, _:= os.OpenFile(doc.LOCATION+"/"+doc.PUB+"."+doc.NAME+".yaml", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
slog.Debug("Create the basic yaml")
if err != nil {
slog.Error(err.Error())
}
err = template.ExecuteTemplate(yamlFile, "yaml", doc)
if err != nil {
slog.Error(err.Error())
}
}

View File

@@ -34,7 +34,7 @@
</div>
<!-- <div> -->
<form action="/upload" method="post" enctype="multipart/form-data">
<form action="/upload" method="post" enctype="multipart/form-data" onsubmit="">
<input type="text" name="filename" placeholder="Selected file" readonly>
<input type="file" name="file" id="file" onchange="document.forms[0].filename.value = this.files[0].name">
<button class="btn" type="submit">Upload</button>

View File

@@ -2,7 +2,7 @@
<div class="container">
<h1>Upload a File</h1>
<form action="/upload" method="post" enctype="multipart/form-data" target="noframe">
<form action="/upload" method="post" enctype="multipart/form-data" target="noframe" onsubmit="showContainer('form-container')">
<div class="upload-btn-wrapper">
<button class="btn">Upload a file</button>
<input type="file" name="myFile" accept=".zip, .exe, .msi" />
@@ -12,7 +12,7 @@
<button type="button" onclick="showContainer('form-container')" >fubarus</button>
</div>
<div class="form-container" oncontextmenu="showContainer('form-container')" onclick="updateForm('/pkg')">
<form>
<form action="/ren", method="put" enctype="multipart/form-data" id="packageProperties">
<div class="form-group">
<label for="Vendor">Vendor</label>
<input type="text" id="Vendor" name="Vendor" onclick="updateForm('/pkg','Vendor')">

28
main.go
View File

@@ -10,6 +10,7 @@ import (
"log/slog"
"net/http"
"os"
"regexp"
"strings"
"time"
@@ -297,7 +298,7 @@ func upload() http.Handler {
func createPackageAndRename() http.Handler{
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){
slog.Debug(req.Host)
})
}
// index creates an HTTP handler that serves the main page with data from the database.
@@ -342,7 +343,31 @@ func index(sqldb *sql.DB, lang string) http.Handler {
})
}
func renameForFile() http.Handler{
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
init:=req.FormValue("Vendor")
init=string(init[0])
regexext:= regexp.MustCompile(`\.[\u\l]{1,5}$`)
extention:=regexext.FindString(req.FormValue("InstallerUrl"))
yamlmodel:=yaml{
PUB: req.FormValue("Vendor"),
HASH: req.FormValue("InstallerSha256"),
URL: req.FormValue("InstallerUrl"),
NAME: req.FormValue("Package"),
PID: req.FormValue("Vendor")+"."+req.FormValue("Package"),
VER: req.FormValue("PackageVersion"),
INIT: init,
LOCATION: os.Getenv("packagesDirectory")+"/"+init+"/"+req.FormValue("Vendor")+"/"+req.FormValue("Package")+"/"+req.FormValue("PackageVersion"),
FILELOCATION: os.Getenv("installationDirectory")+"/"+req.FormValue("Vendor")+"."+req.FormValue("Package")+".v."+req.FormValue("PackageVersion")+extention ,
}
CreateDirectoryInPackageDir(yamlmodel)
CreateYaml(yamlmodel)
// fur:=
// slog.Debug(fur)
})
}
// public serves static files from the "public" directory.
// Returns: An http.Handler that serves static files.
func public() http.Handler {
@@ -384,6 +409,7 @@ func main() {
mux.Handle("/up", uploadFileForServer(db,"eng"))
mux.Handle("/upload",upload())
mux.Handle("/pkg",getJson(db))
mux.Handle("/ren",renameForFile())
addr := fmt.Sprintf(":%s", "12312")
server := http.Server{
Addr: addr,

View File

@@ -3,17 +3,17 @@ package main
import (
"crypto/sha256"
"database/sql"
"encoding/hex"
"fmt"
"html/template"
"log/slog"
"net/http"
"os"
"os/exec"
"encoding/hex"
"regexp"
"runtime"
"strconv"
"strings"
"html/template"
_ "modernc.org/sqlite"
)
@@ -38,6 +38,18 @@ type packages struct {
Warning bool
Element *elements
}
type yaml struct {
PID string
VER string
TYPE string
URL string
HASH string
PUB string
NAME string
INIT string
LOCATION string
FILELOCATION string
}
// ConvertStringsToPackage converts a slice of strings to a packages struct.
// It returns an error if the input slice does not have exactly 6 elements or if the Warning value cannot be parsed as a boolean.
@@ -145,14 +157,14 @@ func getVendor(data map[string]string) string {
for key, val := range data {
switch key {
case "Author":
return strings.ToLower(strings.Replace(val," ","",-1))
return strings.ToLower(strings.Replace(val, " ", "", -1))
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))
return strings.ToLower(strings.Replace(val, " ", "", -1))
case "Publisher":
return strings.ToLower(strings.Replace(val," ","",-1))
return strings.ToLower(strings.Replace(val, " ", "", -1))
}
}
@@ -162,32 +174,32 @@ func getProgram(data map[string]string) string {
for key, val := range data {
switch key {
case "Title":
return strings.ToLower(strings.Replace(val," ","",-1))
return strings.ToLower(strings.Replace(val, " ", "", -1))
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))
return strings.ToLower(strings.Replace(val, " ", "", -1))
case "Subject":
return strings.ToLower(strings.Replace(val," ","",-1))
return strings.ToLower(strings.Replace(val, " ", "", -1))
}
}
return ""
}
func getVersion(data map[string]string) string {
replacer:=regexp.MustCompile(`[, ]+`)
replacer := regexp.MustCompile(`[, ]+`)
for key, val := range data {
switch key {
case "Version":
return replacer.ReplaceAllString(val,".")
return replacer.ReplaceAllString(val, ".")
case "Product Version":
return replacer.ReplaceAllString(val,".")
return replacer.ReplaceAllString(val, ".")
case "ProductVersion":
return replacer.ReplaceAllString(val,".")
return replacer.ReplaceAllString(val, ".")
case "File Version":
return replacer.ReplaceAllString(val,".")
return replacer.ReplaceAllString(val, ".")
case "FileVersion":
return replacer.ReplaceAllString(val,".")
return replacer.ReplaceAllString(val, ".")
}
}
return ""
@@ -198,7 +210,7 @@ func detectProblems(data map[string]string) bool {
if !err || (exe == "exe" && !(mime == "application/octet-stream")) {
return false
}
if (exe != "msi" && exe != "exe" && exe != "zip") {
if exe != "msi" && exe != "exe" && exe != "zip" {
return false
}
return true
@@ -232,14 +244,14 @@ func moveToNewLocationAndName(data map[string]string) string {
func createObject(object map[string]string) jsonStruct {
if detectProblems(object) {
prop := jsonStruct{
Vendor: getVendor(object) ,
Vendor: getVendor(object),
Package: getProgram(object),
Version: getVersion(object),
Type: getInstallerType(object),
}
loc, _ := os.ReadFile(object["Directory"] + "/" + object["File Name"])
chksum:=sha256.Sum256(loc)
chksum := sha256.Sum256(loc)
prop.Checksum = hex.EncodeToString(chksum[:])
lc := moveToNewLocationAndName(object)
prop.Url = os.Getenv("uri") + lc
@@ -267,11 +279,11 @@ func getJson(sqldb *sql.DB) http.Handler {
if err != nil {
slog.Error(err.Error())
}
temp,err:=template.ParseFiles("html/lastob.json")
temp, err := template.ParseFiles("html/lastob.json")
if err != nil {
slog.Error(err.Error())
}
err=temp.ExecuteTemplate(res, "main", jsonelement)
err = temp.ExecuteTemplate(res, "main", jsonelement)
if err != nil {
slog.Error(err.Error())
}

View File

@@ -160,3 +160,8 @@ function updateForm(uri, eid){
console.log(content)
})
}
function updateFormFields(...args){
args.forEach(element => {
updateForm('/pkg', element)
});
}