Skip to content

Commit 9bd466f

Browse files
committed
htmx improved requests sending; improved password representations
1 parent b70e645 commit 9bd466f

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

internal/api/password/show_password/password.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package show_password
33
import (
44
"encoding/base64"
55
"io"
6-
"log"
6+
"log/slog"
77
"net/http"
88
"path/filepath"
99

@@ -15,6 +15,10 @@ import (
1515

1616
templ "pass_web/internal/api/template"
1717
)
18+
type PasswordTempl struct {
19+
PasswordFile string
20+
EncodedContent string
21+
}
1822

1923
func Handler(w http.ResponseWriter, r *http.Request) {
2024
t := templ.NewTemplate()
@@ -24,9 +28,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
2428
passwordFile := passwordItem.Password
2529

2630
passwordPath := passwordItem.Path
27-
passwordPath = filepath.Join(passwordPath, passwordItem.Password)
31+
passwordPath = filepath.Join(passwordPath, passwordFile)
2832

29-
log.Println("Path password ", passwordPath)
3033
file, err := os.Open(passwordPath)
3134

3235
if err != nil {
@@ -38,11 +41,12 @@ func Handler(w http.ResponseWriter, r *http.Request) {
3841

3942
w.Header().Set("Content-Type", "text/html")
4043

41-
t.Render(w, "password", struct {
42-
PasswordFile string
43-
EncodedContent string
44-
}{
45-
PasswordFile: passwordFile,
44+
baseDir := filepath.Base(passwordItem.Path)
45+
relativeFilename := filepath.Join(baseDir, passwordFile)
46+
slog.Info("Password show ", "baseDir", baseDir, "relativeFilename", relativeFilename)
47+
48+
t.Render(w, "password", PasswordTempl{
49+
PasswordFile: relativeFilename,
4650
EncodedContent: encodedContent,
4751
})
4852
}

templates/show.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Show
2020
{{end}}
2121

2222
hx-swap="innerHTML"
23-
hx-trigger="click"
23+
hx-trigger="click consume"
2424
>
2525
{{if .IsDir}}
2626
<span class="text-lg font-semibold">{{ .Password }}</span>
@@ -41,7 +41,8 @@ Show
4141
hx-target="closest div.password-item"
4242
hx-swap="outerHTML"
4343
hx-confirm="Are you sure you want to delete this password?"
44-
onclick="event.stopPropagation()">
44+
hx-trigger="click consume"
45+
>
4546
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
4647
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
4748
</svg>

0 commit comments

Comments
 (0)