forms now work again, DB connection doesn't really yet

templ
Johannes Bülow 2024-01-05 14:05:58 +01:00
parent 1795e770f2
commit 6b2e01d0fc
Signed by untrusted user who does not match committer: jmb
GPG Key ID: B56971CF7B8F83A6
16 changed files with 218 additions and 83 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ db.sqlite
filestore/*
filegate
.vagrant/*
storage/*
### Linux template
*~

View File

@ -4,12 +4,13 @@ release: deps templ
dev: templ
go build .
./filegate -p=false
./filegate -p=false --localfs=./storage
clean:
rm -f filegate
# rm -f config.yaml
rm -f db.sqlite
rm -rf storage/
templ:
rm -f web/templates/*_templ.go

View File

@ -49,13 +49,12 @@ Frontend tooling and Bulma CSS`,
Run: func(cmd *cobra.Command, args []string) {
db.ConnectDB()
// Check if local Filesystem should be used
log.Print(localfs, viper.GetString("localfs"))
// override any Filesystem declared via config file with the cli arg
viper.Set("localfs", localfs)
if localfs == "" || viper.GetString("localfs") == "" {
files.MinioConnect()
files.MinioSetup()
} else {
// override any Filesystem declared via config file with the cli arg
viper.Set("localfs", localfs)
}
web.Router(production)
},

View File

@ -58,6 +58,7 @@ type Attachment struct {
Name string
Comment string
Blob string
FileID uint
}
type FileProperties struct {
@ -71,6 +72,7 @@ type FileProperties struct {
FileCmd string
Extension string
Url string
FileID uint
}
type Container struct {

View File

@ -58,7 +58,7 @@ func DownloadFile(rawURL string, blob string, id uint) (uint, error) {
return 0, err
}
} else {
err := localfiles.PutObject(viper.GetString("localfs"), blob, response.Body, response.ContentLength, contentType)
err := localfiles.PutObject(viper.GetString("localfs"), blob, response.Body)
if err != nil {
log.Printf("Could not create File object: %v \n", err)
return 0, err

View File

@ -21,7 +21,6 @@ func UploadFile(file *multipart.FileHeader, name string, url string, comment str
log.Printf("Could not create File object: %v \n", err)
return 0, err
}
fileSize := file.Size
contentType := file.Header.Get("ContentType")
fileID, err := db.CreateFile(name, url, comment, blob)
if err != nil {
@ -43,7 +42,7 @@ func UploadFile(file *multipart.FileHeader, name string, url string, comment str
}
log.Printf("Successfully uploaded %s of size %d\n", blob, objectInfo.Size)
} else {
err := localfiles.PutObject(viper.GetString("localfs"), blob, fileReader, file.Size, contentType)
err := localfiles.PutObject(viper.GetString("localfs"), blob, fileReader)
if err != nil {
log.Printf("Could not create File object: %v \n", err)
return 0, err

View File

@ -2,15 +2,28 @@ package localfiles
import (
"io"
"os"
"path/filepath"
)
func PutObject(
path string,
blob string,
reader io.Reader,
length int64,
mimeType string,
) error {
fullPath, err := filepath.Abs(filepath.Join(path, blob))
if err != nil {
return err
}
file, err := os.Create(fullPath)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, reader)
if err != nil {
return err
}
return nil
}

View File

@ -10,14 +10,24 @@ templ loginForm() {
</div>
<div class="field">
<div class="control">
<button class="button is-primary" type="submit" hx-trigger="click">Login</button>
<button class="button is-primary" type="submit">Login</button>
</div>
</div>
</form>
}
templ uploadForm() {
<form id="uploadForm" name="uploadform" action="/file/new/upload" method="POST" hx-post="/file/new/upload">
<form
id="uploadForm"
name="uploadform"
action="/file/new/upload"
method="POST"
enctype="multipart/form-data"
hx-post="/file/new/upload"
hx-target="#upload-options"
hx-swap="outerHTML"
>
<h2 class="title">Upload </h2>
<h3 class="subtitle">Upload a suspicious File to Filegate </h3>
<div class="field">
<label class="label">File Name</label>
@ -29,7 +39,7 @@ templ uploadForm() {
</div>
<div class="file has-name is-boxed">
<label class="file-label">
<input class="file-input" type="file" name="resume"/>
<input name="file" class="file-input" type="file" name="resume"/>
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
@ -45,14 +55,30 @@ templ uploadForm() {
</div>
<div class="field">
<div class="control">
<button class="button is-primary" type="submit" hx-trigger="click">Submit</button>
<button class="button is-primary" type="submit">Submit</button>
</div>
</div>
<progress id="progress" value="0" max="100"></progress>
</form>
<script>
htmx.on('#uploadForm', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>
}
templ urlDownloadForm() {
<form id="urldownload" name="urldownload" action="/file/new/download" method="POST" hx-post="/file/new/download">
<form
id="urldownload"
name="urldownload"
action="/file/new/download"
method="POST"
enctype="multipart/form-data"
hx-post="/file/new/download"
hx-target="#upload-options"
hx-swap="outerHTML"
>
<h2 class="title">Download </h2>
<h3 class="subtitle">tries to directly download a file. Might or might not work, depending on how the Website is made</h3>
<div class="field">
<label class="label">File Name</label>
@ -68,14 +94,24 @@ templ urlDownloadForm() {
</div>
<div class="field">
<div class="control">
<button class="button is-primary" type="submit" hx-trigger="click">Submit</button>
<button class="button is-primary" type="submit">Submit</button>
</div>
</div>
</form>
}
templ browserDownloadForm() {
<form id="urldownload" name="urldownload" action="/file/new/browser" method="POST" hx-post="/file/new/browser" hx-target="#upload-options" hx-swap="outerHTML">
<form
id="urldownload"
name="urldownload"
action="/file/new/browser"
enctype="multipart/form-data"
method="POST"
hx-post="/file/new/browser"
hx-target="#upload-options"
hx-swap="outerHTML"
>
<h2 class="title">Download-Browser </h2>
<h3 class="subtitle">Opens a Browser inside a container to download a suspicious file.</h3>
<div class="field">
<label class="label">File Name</label>
@ -91,7 +127,7 @@ templ browserDownloadForm() {
</div>
<div class="field">
<div class="control">
<button class="button is-primary" type="submit" hx-trigger="click">Open</button>
<button class="button is-primary" type="submit">Open</button>
</div>
</div>
</form>

View File

@ -41,7 +41,7 @@ func loginForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <input class=\"input\" type=\"password\" name=\"password\" placeholder=\"************\" required class=\"input\"></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\" hx-trigger=\"click\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <input class=\"input\" type=\"password\" name=\"password\" placeholder=\"************\" required class=\"input\"></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -74,21 +74,30 @@ func uploadForm() templ.Component {
templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"uploadForm\" name=\"uploadform\" action=\"/file/new/upload\" method=\"POST\" hx-post=\"/file/new/upload\"><h3 class=\"subtitle\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"uploadForm\" name=\"uploadform\" action=\"/file/new/upload\" method=\"POST\" enctype=\"multipart/form-data\" hx-post=\"/file/new/upload\" hx-target=\"#upload-options\" hx-swap=\"outerHTML\"><h2 class=\"title\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var6 := `Upload a suspicious File to Filegate `
templ_7745c5c3_Var6 := `Upload `
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2><h3 class=\"subtitle\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var7 := `Upload a suspicious File to Filegate `
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h3><div class=\"field\"><label class=\"label\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var7 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
templ_7745c5c3_Var8 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -96,39 +105,52 @@ func uploadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var8 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"file has-name is-boxed\"><label class=\"file-label\"><input class=\"file-input\" type=\"file\" name=\"resume\"> <span class=\"file-cta\"><span class=\"file-icon\"><i class=\"fas fa-upload\"></i></span> <span class=\"file-label\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var9 := `Choose a file…`
templ_7745c5c3_Var9 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"file has-name is-boxed\"><label class=\"file-label\"><input name=\"file\" class=\"file-input\" type=\"file\" name=\"resume\"> <span class=\"file-cta\"><span class=\"file-icon\"><i class=\"fas fa-upload\"></i></span> <span class=\"file-label\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var10 := `Choose a file…`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></span> <span class=\"file-name\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var10 := `Invoice.docm`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></label></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\" hx-trigger=\"click\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var11 := `Submit`
templ_7745c5c3_Var11 := `Invoice.docm`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button></div></div></form>")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></label></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var12 := `Submit`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button></div></div><progress id=\"progress\" value=\"0\" max=\"100\"></progress></form><script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var13 := `
htmx.on('#uploadForm', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -147,17 +169,26 @@ func urlDownloadForm() templ.Component {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var12 := templ.GetChildren(ctx)
if templ_7745c5c3_Var12 == nil {
templ_7745c5c3_Var12 = templ.NopComponent
templ_7745c5c3_Var14 := templ.GetChildren(ctx)
if templ_7745c5c3_Var14 == nil {
templ_7745c5c3_Var14 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"urldownload\" name=\"urldownload\" action=\"/file/new/download\" method=\"POST\" hx-post=\"/file/new/download\"><h3 class=\"subtitle\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"urldownload\" name=\"urldownload\" action=\"/file/new/download\" method=\"POST\" enctype=\"multipart/form-data\" hx-post=\"/file/new/download\" hx-target=\"#upload-options\" hx-swap=\"outerHTML\"><h2 class=\"title\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var13 := `tries to directly download a file. Might or might not work, depending on how the Website is made`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
templ_7745c5c3_Var15 := `Download `
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2><h3 class=\"subtitle\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var16 := `tries to directly download a file. Might or might not work, depending on how the Website is made`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -165,8 +196,8 @@ func urlDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var14 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
templ_7745c5c3_Var17 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -174,8 +205,8 @@ func urlDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var15 := `URL`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
templ_7745c5c3_Var18 := `URL`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -183,17 +214,17 @@ func urlDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var16 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
templ_7745c5c3_Var19 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\" hx-trigger=\"click\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var17 := `Submit`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
templ_7745c5c3_Var20 := `Submit`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var20)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -216,17 +247,26 @@ func browserDownloadForm() templ.Component {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var18 := templ.GetChildren(ctx)
if templ_7745c5c3_Var18 == nil {
templ_7745c5c3_Var18 = templ.NopComponent
templ_7745c5c3_Var21 := templ.GetChildren(ctx)
if templ_7745c5c3_Var21 == nil {
templ_7745c5c3_Var21 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"urldownload\" name=\"urldownload\" action=\"/file/new/browser\" method=\"POST\" hx-post=\"/file/new/browser\" hx-target=\"#upload-options\" hx-swap=\"outerHTML\"><h3 class=\"subtitle\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"urldownload\" name=\"urldownload\" action=\"/file/new/browser\" enctype=\"multipart/form-data\" method=\"POST\" hx-post=\"/file/new/browser\" hx-target=\"#upload-options\" hx-swap=\"outerHTML\"><h2 class=\"title\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var19 := `Opens a Browser inside a container to download a suspicious file.`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
templ_7745c5c3_Var22 := `Download-Browser `
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2><h3 class=\"subtitle\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var23 := `Opens a Browser inside a container to download a suspicious file.`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -234,8 +274,8 @@ func browserDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var20 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var20)
templ_7745c5c3_Var24 := `File Name`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var24)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -243,8 +283,8 @@ func browserDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var21 := `Start-URL`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21)
templ_7745c5c3_Var25 := `Start-URL`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var25)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -252,17 +292,17 @@ func browserDownloadForm() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var22 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22)
templ_7745c5c3_Var26 := `Comment/Description`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var26)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\" hx-trigger=\"click\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <textarea class=\"textarea\" name=\"comment\" placeholder=\"e.g. This is an old Microsoft Office Format\"></textarea></div><div class=\"field\"><div class=\"control\"><button class=\"button is-primary\" type=\"submit\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var23 := `Open`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23)
templ_7745c5c3_Var27 := `Open`
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var27)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

View File

@ -77,11 +77,17 @@ templ loginButton(loggedIn bool) {
}
}
templ errorMessage(title string, content string) {
<article class="message container">
templ ErrorMessage(title string, content string) {
<article class="message container" id="errorContainer">
<div class="message-header">
<p>{ title }</p>
<button class="delete" aria-label="delete"></button>
<button
class="delete"
aria-label="delete"
hx-get="/empty.html"
hx-target="#errorContainer"
hx-swap="outerHTML"
></button>
</div>
<div class="message-body">
{ content }

View File

@ -378,7 +378,7 @@ func loginButton(loggedIn bool) templ.Component {
})
}
func errorMessage(title string, content string) templ.Component {
func ErrorMessage(title string, content string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@ -391,7 +391,7 @@ func errorMessage(title string, content string) templ.Component {
templ_7745c5c3_Var34 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<article class=\"message container\"><div class=\"message-header\"><p>")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<article class=\"message container\" id=\"errorContainer\"><div class=\"message-header\"><p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -400,7 +400,7 @@ func errorMessage(title string, content string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p><button class=\"delete\" aria-label=\"delete\"></button></div><div class=\"message-body\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p><button class=\"delete\" aria-label=\"delete\" hx-get=\"/empty.html\" hx-target=\"#errorContainer\" hx-swap=\"outerHTML\"></button></div><div class=\"message-body\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

View File

@ -12,7 +12,7 @@ templ wrapBase(metaContent utils.MetaContent, title string, err error) {
<body class="has-navbar-fixed-top">
@navbar(metaContent.IsLoggedIn)
if err != nil {
@errorMessage("Error", err.Error())
@ErrorMessage("Error", err.Error())
}
{ children... }
@footer(metaContent.Timestamp)
@ -93,3 +93,7 @@ templ NewFilePage(metaContent utils.MetaContent, title string, err error) {
</div>
}
}
templ Empty() {
<div></div>
}

View File

@ -45,7 +45,7 @@ func wrapBase(metaContent utils.MetaContent, title string, err error) templ.Comp
return templ_7745c5c3_Err
}
if err != nil {
templ_7745c5c3_Err = errorMessage("Error", err.Error()).Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = ErrorMessage("Error", err.Error()).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -348,3 +348,27 @@ func NewFilePage(metaContent utils.MetaContent, title string, err error) templ.C
return templ_7745c5c3_Err
})
}
func Empty() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var17 := templ.GetChildren(ctx)
if templ_7745c5c3_Var17 == nil {
templ_7745c5c3_Var17 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
})
}

9
web/ui/empty.go Normal file
View File

@ -0,0 +1,9 @@
package ui
import (
"github.com/gin-gonic/gin"
)
func empty(c *gin.Context) {
c.HTML(200, "", "")
}

View File

@ -71,7 +71,7 @@ func newFileError(c *gin.Context, err error) {
metaContent := utils.GenMetaContent(c)
metaContent.ErrorTitle = "Error"
metaContent.ErrorText = err.Error()
c.HTML(http.StatusOK, "", templates.NewFilePage(utils.GenMetaContent(c), "New File", err))
c.HTML(http.StatusOK, "", templates.ErrorMessage("Could not create File", err.Error()))
log.Println(err)
return
}

View File

@ -12,6 +12,7 @@ func GroupWeb(router *gin.Engine) *gin.Engine {
router.POST("/login.html", postLogin)
file := router.Group("/file/")
file.GET("/", getFileListPage)
file.GET("/empty.html", empty)
file.GET("/new/", getNewFile)
file.POST("/new/upload", postNewFileUpload)
file.POST("/new/download", postNewFileDownload)