commit 0341fb8
delthas
·
2025-08-03 21:17:08 +0000 UTC
parent 4c62442
Make UPLOAD paths relative to the user home directory Closes: https://todo.sr.ht/~delthas/senpai/211
2 files changed,
+13,
-4
+4,
-0
1@@ -5,6 +5,7 @@ import (
2 "fmt"
3 "net/url"
4 "os"
5+ "path/filepath"
6 "sort"
7 "strconv"
8 "strings"
9@@ -523,6 +524,9 @@ func commandDoUpload(app *App, args []string) (err error) {
10 return fmt.Errorf("file upload is not supported on this server; try using soju and enabling file upload")
11 }
12 path := args[0]
13+ if home, err := os.UserHomeDir(); err == nil && !filepath.IsAbs(path) {
14+ path = filepath.Join(home, path)
15+ }
16
17 fi, err := os.Stat(path)
18 if err != nil {
+9,
-4
1@@ -193,10 +193,15 @@ func (app *App) completionsUpload(cs []ui.Completion, cursorIdx int, text []rune
2 dirPath := ""
3 dirPrefix := ""
4 if path == "" {
5- if filepath.Separator != '/' {
6- return cs
7+ home, err := os.UserHomeDir()
8+ if err != nil {
9+ if filepath.Separator != '/' {
10+ return cs
11+ }
12+ dirPath = "/"
13+ } else {
14+ dirPath = home
15 }
16- dirPath = "/"
17 } else if strings.HasSuffix(path, string(filepath.Separator)) {
18 dirPath = path
19 } else {
20@@ -224,7 +229,7 @@ func (app *App) completionsUpload(cs []ui.Completion, cursorIdx int, text []rune
21 if isDir {
22 name += string(filepath.Separator)
23 }
24- if path == "" {
25+ if dirPrefix == "/" {
26 name = "/" + name
27 }
28 if name == dirPrefix {