From 832715f8610b2bb874a392017ff1b9d608abfec7 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Tue, 14 Jul 2020 08:46:20 +0200 Subject: [PATCH] Backend: Improve Dsc regular expression and add test --- internal/config/filenames_test.go | 14 ++++++++++++++ pkg/fs/id.go | 2 +- pkg/fs/id_test.go | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/config/filenames_test.go b/internal/config/filenames_test.go index 2c590e1b5..d8c1909e4 100644 --- a/internal/config/filenames_test.go +++ b/internal/config/filenames_test.go @@ -61,3 +61,17 @@ func TestConfig_TestdataPath(t *testing.T) { assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/testdata", c.TestdataPath()) } + +func TestConfig_CreateDirectories(t *testing.T) { + c := NewTestConfig() + err := c.CreateDirectories() + + if err != nil { + t.Fatal(err) + } +} + +func TestConfig_ConfigFile2(t *testing.T) { + c := NewTestConfig() + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/testdata", c.ConfigFile()) +} diff --git a/pkg/fs/id.go b/pkg/fs/id.go index 822e72b26..a9cf1d846 100644 --- a/pkg/fs/id.go +++ b/pkg/fs/id.go @@ -6,7 +6,7 @@ import ( "github.com/photoprism/photoprism/pkg/rnd" ) -var DscNameRegexp = regexp.MustCompile("\\D{3}[\\d_]\\d{4,8}_?\\d{0,6}(.JPG)?") +var DscNameRegexp = regexp.MustCompile("\\D{3}[\\d_]\\d{4,8}_?\\d{0,6}_?\\d{0,6}(.JPG)?") var UniqueNameRegexp = regexp.MustCompile("[a-f0-9]{8,16}_[a-f0-9]{6,16}_[A-Za-z0-9]{1,20}_?[A-Za-z0-9]{0,4}") // Example: 8263987746_d0a6055c58_o var UUIDNameRegexp = regexp.MustCompile("[A-Fa-f0-9\\-]{16,36}_?[A-Za-z0-9_]{0,20}") // Example: 8263987746_d0a6055c58_o diff --git a/pkg/fs/id_test.go b/pkg/fs/id_test.go index 3cba47711..b9793739b 100644 --- a/pkg/fs/id_test.go +++ b/pkg/fs/id_test.go @@ -95,6 +95,9 @@ func TestIsDscName(t *testing.T) { assert.False(t, IsDscName("550e8400-e29b-11d4-a716-446655440000")) assert.True(t, IsDscName("IMG_0599.JPG")) assert.True(t, IsDscName("IMG_20190721_095643.JPG")) + assert.True(t, IsDscName("IMG_20190119_135810_145")) + //TODO + //assert.True(t, IsDscName("IMG_1059_2048px")) assert.True(t, IsDscName("IMG_20190721_095643")) assert.True(t, IsDscName("DSC_20190721_095643")) assert.True(t, IsDscName("DSC10599"))