From a056b045a9a726d0fddc6fa4825074fad5c7af78 Mon Sep 17 00:00:00 2001 From: breel Date: Fri, 31 Jul 2020 23:09:29 -0600 Subject: [PATCH] attachments now format absolute url --- public/vue/dndex-ui | 2 +- view/who.go | 15 +++++++++++++++ view/who_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/public/vue/dndex-ui b/public/vue/dndex-ui index 0b55398..c5da36f 160000 --- a/public/vue/dndex-ui +++ b/public/vue/dndex-ui @@ -1 +1 @@ -Subproject commit 0b553984035d46f1b150d600303001b4164f3124 +Subproject commit c5da36f592820312e10d05ff27c32d0ef644f282 diff --git a/view/who.go b/view/who.go index 1e98330..3efee80 100644 --- a/view/who.go +++ b/view/who.go @@ -7,10 +7,13 @@ import ( "fmt" "io" "io/ioutil" + "local/dndex/config" "local/dndex/storage" "local/dndex/storage/entity" "local/dndex/storage/operator" "net/http" + "net/url" + "path" "regexp" "sort" "strings" @@ -75,6 +78,18 @@ func whoGet(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter, } one := ones[0] + baseUrl := *r.URL + if baseUrl.Host == "" { + baseUrl.Host = r.Host + } + baseUrl.Path = "" + baseUrl.RawQuery = "" + for k := range one.Attachments { + if _, err := url.Parse(one.Attachments[k]); err != nil || !strings.Contains(one.Attachments[k], ":") { + one.Attachments[k] = path.Join(baseUrl.String(), config.New().FilePrefix, namespace, one.Attachments[k]) + } + } + if !light && len(one.Connections) > 0 { ones, err := g.ListCaseInsensitive(r.Context(), namespace, one.Peers()...) if err != nil { diff --git a/view/who_test.go b/view/who_test.go index 7d8707f..d6029aa 100644 --- a/view/who_test.go +++ b/view/who_test.go @@ -14,6 +14,7 @@ import ( "net/http/httptest" "net/url" "os" + "path" "regexp" "sort" "strings" @@ -95,6 +96,21 @@ func TestWho(t *testing.T) { if len(o.Connections) != len(iwant.Connections) { t.Fatal(len(o.Connections), len(iwant.Connections)) } + if len(o.Attachments) != len(iwant.Attachments) { + t.Fatal(len(o.Attachments), len(iwant.Attachments)) + } + for k := range o.Attachments { + if _, ok := iwant.Attachments[k]; !ok { + t.Fatal(k, ok) + } + if o.Attachments[k] == iwant.Attachments[k] { + t.Fatal(k, o.Attachments[k], iwant.Attachments[k]) + } + if !strings.HasSuffix(o.Attachments[k], path.Join(config.New().FilePrefix, "col", iwant.Attachments[k])) { + t.Fatal(k, o.Attachments[k], iwant.Attachments[k]) + } + } + iwant.Attachments = o.Attachments iwant.Connections = o.Connections iwant.Modified = 0 o.Modified = 0 @@ -125,6 +141,7 @@ func TestWho(t *testing.T) { t.Fatal(len(o.Connections), len(iwant.Connections)) } iwant.Connections = o.Connections + iwant.Attachments = o.Attachments iwant.Modified = 0 o.Modified = 0 if fmt.Sprint(o) != fmt.Sprint(iwant) { @@ -162,6 +179,7 @@ func TestWho(t *testing.T) { t.Fatal(len(o.Connections), len(iwant.Connections)) } iwant.Connections = o.Connections + iwant.Attachments = o.Attachments iwant.Modified = 0 o.Modified = 0 if fmt.Sprint(o) != fmt.Sprint(iwant) { @@ -197,6 +215,7 @@ func TestWho(t *testing.T) { t.Fatal(len(o.Connections), len(iwant.Connections)) } iwant.Connections = o.Connections + iwant.Attachments = o.Attachments iwant.Modified = 0 o.Modified = 0 if fmt.Sprint(o) != fmt.Sprint(iwant) { @@ -528,6 +547,8 @@ func TestWho(t *testing.T) { } got.Connections = nil from.Connections = nil + got.Attachments = nil + from.Attachments = nil if fmt.Sprint(got) != fmt.Sprint(from) { t.Fatalf("without connections and modified, got != want: want \n %+v, got \n %+v", from, got) } @@ -569,6 +590,7 @@ func TestWho(t *testing.T) { t.Fatal(len(got.Connections), len(want.Connections)+1) } got.Connections = want.Connections + got.Attachments = want.Attachments got.Modified = 0 want.Modified = 0 if fmt.Sprint(got) != fmt.Sprint(want) { @@ -753,6 +775,7 @@ func TestWho(t *testing.T) { b.Modified = 0 o.Connections[k] = b } + o.Attachments = want.Attachments if fmt.Sprint(o) != fmt.Sprint(want) { t.Fatalf("GET put != expected: want:\n%+v, got \n%+v", want, o) } @@ -822,6 +845,9 @@ func randomOne() entity.One { Text: "text-" + uuid.New().String()[:5], Modified: time.Now().UnixNano(), Connections: map[string]entity.One{}, + Attachments: map[string]string{ + uuid.New().String()[:5]: uuid.New().String()[:5], + }, } }