attachments now format absolute url
parent
e706548f55
commit
a056b045a9
|
|
@ -1 +1 @@
|
|||
Subproject commit 0b553984035d46f1b150d600303001b4164f3124
|
||||
Subproject commit c5da36f592820312e10d05ff27c32d0ef644f282
|
||||
15
view/who.go
15
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 {
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue