diff --git a/client.go b/client.go index e9af7c1..cd98268 100644 --- a/client.go +++ b/client.go @@ -23,6 +23,10 @@ const ( // New is used to create a new Client to authenticate with // Photoprism. func New(connectionString string) *Client { + for strings.HasSuffix(connectionString, "/") { + connectionString = connectionString[:len(connectionString)-1] + } + c := &Client{ contentType: APIContentType, connectionString: connectionString, @@ -30,6 +34,10 @@ func New(connectionString string) *Client { return c } +func (c *Client) ConnectionString() string { + return c.connectionString +} + // Client represents a client to a Photoprism application type Client struct { v1client *v1.V1Client diff --git a/sample-app/photoprism/storage/albums/album/aqohkx21cwlrrs71.yml b/sample-app/photoprism/storage/albums/album/aqohkx21cwlrrs71.yml new file mode 100755 index 0000000..019e883 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohkx21cwlrrs71.yml @@ -0,0 +1,9 @@ +UID: aqohkx21cwlrrs71 +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:27:02Z +UpdatedAt: 2021-02-13T21:27:02Z +DeletedAt: 2021-02-13T21:27:02.438478307Z diff --git a/sample-app/photoprism/storage/albums/album/aqohkx21dyhq6xa6.yml b/sample-app/photoprism/storage/albums/album/aqohkx21dyhq6xa6.yml new file mode 100755 index 0000000..7d198f3 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohkx21dyhq6xa6.yml @@ -0,0 +1,9 @@ +UID: aqohkx21dyhq6xa6 +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:27:02Z +UpdatedAt: 2021-02-13T21:27:02Z +DeletedAt: 2021-02-13T21:27:02.460875532Z diff --git a/sample-app/photoprism/storage/albums/album/aqohkx21j9rj6w4f.yml b/sample-app/photoprism/storage/albums/album/aqohkx21j9rj6w4f.yml new file mode 100755 index 0000000..34335b3 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohkx21j9rj6w4f.yml @@ -0,0 +1,9 @@ +UID: aqohkx21j9rj6w4f +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:27:02Z +UpdatedAt: 2021-02-13T21:27:02Z +DeletedAt: 2021-02-13T21:27:02.505591441Z diff --git a/sample-app/photoprism/storage/albums/album/aqohkx22im2tmqpd.yml b/sample-app/photoprism/storage/albums/album/aqohkx22im2tmqpd.yml new file mode 100755 index 0000000..192715f --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohkx22im2tmqpd.yml @@ -0,0 +1,10 @@ +UID: aqohkx22im2tmqpd +Slug: testalbum +Type: album +Title: TestAlbum +Description: An updated album description +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:27:02Z +UpdatedAt: 2021-02-13T21:27:02.386442236Z +DeletedAt: 2021-02-13T21:27:02.395711612Z diff --git a/sample-app/photoprism/storage/albums/album/aqohl0w1s0skc6f0.yml b/sample-app/photoprism/storage/albums/album/aqohl0w1s0skc6f0.yml new file mode 100755 index 0000000..629408e --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohl0w1s0skc6f0.yml @@ -0,0 +1,9 @@ +UID: aqohl0w1s0skc6f0 +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:29:21Z +UpdatedAt: 2021-02-13T21:29:21Z +DeletedAt: 2021-02-13T21:29:20.538356219Z diff --git a/sample-app/photoprism/storage/albums/album/aqohl0w2dwab02xe.yml b/sample-app/photoprism/storage/albums/album/aqohl0w2dwab02xe.yml new file mode 100755 index 0000000..41a1a9f --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohl0w2dwab02xe.yml @@ -0,0 +1,9 @@ +UID: aqohl0w2dwab02xe +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:29:20Z +UpdatedAt: 2021-02-13T21:29:20Z +DeletedAt: 2021-02-13T21:29:20.486868765Z diff --git a/sample-app/photoprism/storage/albums/album/aqohl0w2xt57x1cb.yml b/sample-app/photoprism/storage/albums/album/aqohl0w2xt57x1cb.yml new file mode 100755 index 0000000..885ea41 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohl0w2xt57x1cb.yml @@ -0,0 +1,10 @@ +UID: aqohl0w2xt57x1cb +Slug: testalbum +Type: album +Title: TestAlbum +Description: An updated album description +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:29:20Z +UpdatedAt: 2021-02-13T21:29:20.397458176Z +DeletedAt: 2021-02-13T21:29:20.415107277Z diff --git a/sample-app/photoprism/storage/albums/album/aqohl0wdspiitn0a.yml b/sample-app/photoprism/storage/albums/album/aqohl0wdspiitn0a.yml new file mode 100755 index 0000000..78ae437 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqohl0wdspiitn0a.yml @@ -0,0 +1,9 @@ +UID: aqohl0wdspiitn0a +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-13T21:29:20Z +UpdatedAt: 2021-02-13T21:29:20Z +DeletedAt: 2021-02-13T21:29:20.461857977Z diff --git a/sample-app/photoprism/storage/cache/sessions.json b/sample-app/photoprism/storage/cache/sessions.json index b1aced4..a204d40 100644 --- a/sample-app/photoprism/storage/cache/sessions.json +++ b/sample-app/photoprism/storage/cache/sessions.json @@ -114,6 +114,11 @@ "tokens": null, "expiration": 1613695252131862322 }, + "24227dba42c911f1f3250745252473200d95db38c9006bf6": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613856560374865002 + }, "2521ed30985fb1991e3d1271cbf6e2b53840d614647361af": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -184,6 +189,11 @@ "tokens": null, "expiration": 1613676253240643293 }, + "383cbd715f476ce738e23712a480e3fca123b68f16f2ee69": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613856561720200205 + }, "3bd19dc60e5a515d2624f0d712db8471f433416935c2a045": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -579,6 +589,11 @@ "tokens": null, "expiration": 1613502517447074204 }, + "a69b726d7a6bfab6bac0435a6673d5c390a732470c910f41": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613856423690963485 + }, "a83cc511e399c1dab37468d0c64302bf4b68f7e3df5a1e0b": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -649,6 +664,11 @@ "tokens": null, "expiration": 1613693719704975163 }, + "b9a554547ba1cc81f7d42ea5df395a50968294eb9b574d28": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613856422361372143 + }, "bbdbf96d91d72d87fb819d31d7f175b733164975c1802243": { "user": "uqnzie01i1nypnt9", "tokens": null, diff --git a/sample-app/photoprism/storage/index.db b/sample-app/photoprism/storage/index.db index e310cfd..5c287af 100644 Binary files a/sample-app/photoprism/storage/index.db and b/sample-app/photoprism/storage/index.db differ diff --git a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml index 011d67a..3eb3051 100755 --- a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml +++ b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml @@ -3,7 +3,7 @@ UID: pqnzigq351j2fqgn Type: image Title: A really great photo! TitleSrc: manual -Description: 'Sample App Description: 2021-02-13 13:17:39.073524303 -0800 PST m=+6.526679853' +Description: 'Sample App Description: 2021-02-13 13:29:20.603412741 -0800 PST m=+6.504617892' DescriptionSrc: manual OriginalName: IMG_3044 Year: -1 @@ -13,5 +13,5 @@ Details: Keywords: green, tambourine KeywordsSrc: manual CreatedAt: 2021-02-04T03:17:14.613092062Z -UpdatedAt: 2021-02-13T21:17:39.081685026Z -EditedAt: 2021-02-13T21:17:39Z +UpdatedAt: 2021-02-13T21:29:20.611389111Z +EditedAt: 2021-02-13T21:29:21Z diff --git a/test/regression_test.go b/test/regression_test.go new file mode 100644 index 0000000..3fd7354 --- /dev/null +++ b/test/regression_test.go @@ -0,0 +1,22 @@ +package test + +import ( + "testing" + + "github.com/kris-nova/photoprism-client-go" +) + +// Trailing slash issue +// https://github.com/kris-nova/photoprism-client-go/issues/2 +func TestRegressionIssue2(t *testing.T) { + testStrings := []string{"localhost/", "localhost///////", "localhost//"} + goal := "localhost" + for _, str := range testStrings { + client := photoprism.New(str) + if client.ConnectionString() != goal { + t.Error("Failed to trim suffix / in client connection string") + t.FailNow() + } + } + +}