workign on the yamls
This commit is contained in:
13
YamlTemplates/template.installer.yaml
Normal file
13
YamlTemplates/template.installer.yaml
Normal 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}}
|
13
YamlTemplates/template.locale.en-US.yaml
Normal file
13
YamlTemplates/template.locale.en-US.yaml
Normal 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}}
|
9
YamlTemplates/template.yaml
Normal file
9
YamlTemplates/template.yaml
Normal 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
30
fileOrginize.go
Normal 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())
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- <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="text" name="filename" placeholder="Selected file" readonly>
|
||||||
<input type="file" name="file" id="file" onchange="document.forms[0].filename.value = this.files[0].name">
|
<input type="file" name="file" id="file" onchange="document.forms[0].filename.value = this.files[0].name">
|
||||||
<button class="btn" type="submit">Upload</button>
|
<button class="btn" type="submit">Upload</button>
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Upload a File</h1>
|
<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">
|
<div class="upload-btn-wrapper">
|
||||||
<button class="btn">Upload a file</button>
|
<button class="btn">Upload a file</button>
|
||||||
<input type="file" name="myFile" accept=".zip, .exe, .msi" />
|
<input type="file" name="myFile" accept=".zip, .exe, .msi" />
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<button type="button" onclick="showContainer('form-container')" >fubarus</button>
|
<button type="button" onclick="showContainer('form-container')" >fubarus</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-container" oncontextmenu="showContainer('form-container')" onclick="updateForm('/pkg')">
|
<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">
|
<div class="form-group">
|
||||||
<label for="Vendor">Vendor</label>
|
<label for="Vendor">Vendor</label>
|
||||||
<input type="text" id="Vendor" name="Vendor" onclick="updateForm('/pkg','Vendor')">
|
<input type="text" id="Vendor" name="Vendor" onclick="updateForm('/pkg','Vendor')">
|
||||||
|
28
main.go
28
main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -297,7 +298,7 @@ func upload() http.Handler {
|
|||||||
|
|
||||||
func createPackageAndRename() http.Handler{
|
func createPackageAndRename() http.Handler{
|
||||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){
|
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.
|
// 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.
|
// public serves static files from the "public" directory.
|
||||||
// Returns: An http.Handler that serves static files.
|
// Returns: An http.Handler that serves static files.
|
||||||
func public() http.Handler {
|
func public() http.Handler {
|
||||||
@@ -384,6 +409,7 @@ func main() {
|
|||||||
mux.Handle("/up", uploadFileForServer(db,"eng"))
|
mux.Handle("/up", uploadFileForServer(db,"eng"))
|
||||||
mux.Handle("/upload",upload())
|
mux.Handle("/upload",upload())
|
||||||
mux.Handle("/pkg",getJson(db))
|
mux.Handle("/pkg",getJson(db))
|
||||||
|
mux.Handle("/ren",renameForFile())
|
||||||
addr := fmt.Sprintf(":%s", "12312")
|
addr := fmt.Sprintf(":%s", "12312")
|
||||||
server := http.Server{
|
server := http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
|
18
packages.go
18
packages.go
@@ -3,17 +3,17 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"encoding/hex"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"html/template"
|
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
)
|
)
|
||||||
@@ -38,6 +38,18 @@ type packages struct {
|
|||||||
Warning bool
|
Warning bool
|
||||||
Element *elements
|
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.
|
// 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.
|
// 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.
|
||||||
@@ -198,7 +210,7 @@ func detectProblems(data map[string]string) bool {
|
|||||||
if !err || (exe == "exe" && !(mime == "application/octet-stream")) {
|
if !err || (exe == "exe" && !(mime == "application/octet-stream")) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (exe != "msi" && exe != "exe" && exe != "zip") {
|
if exe != "msi" && exe != "exe" && exe != "zip" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@@ -160,3 +160,8 @@ function updateForm(uri, eid){
|
|||||||
console.log(content)
|
console.log(content)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function updateFormFields(...args){
|
||||||
|
args.forEach(element => {
|
||||||
|
updateForm('/pkg', element)
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user