diff --git a/go.mod b/go.mod index 45dcc982e..ce3c40371 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/disintegration/imaging v1.6.2 github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a github.com/elastic/go-elasticsearch/v8 v8.13.1 - github.com/fivenp/go-identicon v0.0.0-20180326215656-a5b7d5ff972d github.com/gavv/httpexpect/v2 v2.16.0 github.com/go-audio/audio v1.0.0 github.com/go-audio/wav v1.1.0 @@ -37,6 +36,7 @@ require ( github.com/labstack/echo/v4 v4.12.0 github.com/leandro-lugaresi/hub v1.1.1 github.com/lthibault/jitterbug/v2 v2.2.2 + github.com/motoki317/go-identicon v0.0.1 github.com/motoki317/go-waveform v0.0.3 github.com/motoki317/sc v1.8.1 github.com/ncw/swift/v2 v2.0.2 diff --git a/go.sum b/go.sum index 4d1235bcc..09a3ba7f5 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,6 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fivenp/go-identicon v0.0.0-20170128000056-5c327fb4e74a h1:nlaSiFY1VxmQqmmlHEVx5iUYTi2/1Q4utuuA1RxoHfk= -github.com/fivenp/go-identicon v0.0.0-20170128000056-5c327fb4e74a/go.mod h1:OP6goBndFDJFLA3iLwBZRqDKVvFJL7fsYaPa5HnIR0M= github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= @@ -308,6 +306,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/motoki317/go-identicon v0.0.1 h1:PF14Gwx6Qu+fqR9KTMvmKzJCzV3WOwzpisgVxsJjihM= +github.com/motoki317/go-identicon v0.0.1/go.mod h1:c4MUzyFQAOv/N7KYiPjWHK5CkMR0PhxEpSrWGwCY+qs= github.com/motoki317/go-waveform v0.0.3 h1:6efPqPi1VXRtFCIVworPclxzh0ysP2k9+5CwnEv56bg= github.com/motoki317/go-waveform v0.0.3/go.mod h1:qvnSTo335eMOHcawLX9By5yNC+FQ1FFCHe5HkisfUTo= github.com/motoki317/sc v1.8.1 h1:2WcCDvuqwbthjEXey/AMoOsTbsXsyh3b6NTpTzJON7g= diff --git a/service/file/manager_impl_test.go b/service/file/manager_impl_test.go index 0541e587e..39770d115 100644 --- a/service/file/manager_impl_test.go +++ b/service/file/manager_impl_test.go @@ -3,6 +3,7 @@ package file import ( "bytes" "errors" + "github.com/stretchr/testify/require" "image/png" "io" "testing" @@ -96,7 +97,8 @@ func TestManagerImpl_Save(t *testing.T) { data := []byte("test text file") hash := "7e6d5d7ae4965bfecc6d818f76eb832b" - thumb := imaging2.GenerateIcon("test") + thumb, err := imaging2.GenerateIcon("test") + require.NoError(t, err) args := SaveArgs{ FileName: "dummy.png", FileSize: int64(len(data)), @@ -160,7 +162,8 @@ func TestManagerImpl_Save(t *testing.T) { data := []byte("test text file") hash := "7e6d5d7ae4965bfecc6d818f76eb832b" - thumb := imaging2.GenerateIcon("test") + thumb, err := imaging2.GenerateIcon("test") + require.NoError(t, err) args := SaveArgs{ FileName: "dummy.png", FileSize: int64(len(data)), @@ -226,7 +229,8 @@ func TestManagerImpl_Save(t *testing.T) { data := []byte("test text file") hash := "7e6d5d7ae4965bfecc6d818f76eb832b" - thumb := imaging2.GenerateIcon("test") + thumb, err := imaging2.GenerateIcon("test") + require.NoError(t, err) args := SaveArgs{ FileName: "dummy.png", FileSize: int64(len(data)), diff --git a/service/file/utils.go b/service/file/utils.go index ac0b482b9..f0c0cdcbc 100644 --- a/service/file/utils.go +++ b/service/file/utils.go @@ -16,7 +16,10 @@ import ( // 成功した場合、そのファイルのUUIDとnilを返します。 func GenerateIconFile(m Manager, salt string) (uuid.UUID, error) { var img bytes.Buffer - icon := imaging.GenerateIcon(salt) + icon, err := imaging.GenerateIcon(salt) + if err != nil { + return uuid.Nil, err + } if err := png.Encode(&img, icon); err != nil { return uuid.Nil, err diff --git a/utils/imaging/icon.go b/utils/imaging/icon.go index 965ea5063..02b016365 100644 --- a/utils/imaging/icon.go +++ b/utils/imaging/icon.go @@ -3,14 +3,14 @@ package imaging import ( "image" - "github.com/fivenp/go-identicon" + "github.com/motoki317/go-identicon" ) const iconSize = 256 -var iconSettings = qidenticon.DefaultSettings() +var iconSettings = identicon.DefaultSettings() // GenerateIcon アイコン画像を生成します -func GenerateIcon(salt string) image.Image { - return qidenticon.Render(qidenticon.Code(salt), iconSize, iconSettings) +func GenerateIcon(salt string) (image.Image, error) { + return identicon.Render(identicon.Code(salt), iconSize, iconSettings) } diff --git a/utils/imaging/icon_test.go b/utils/imaging/icon_test.go index e12ca1e5e..bbaaf9ed7 100644 --- a/utils/imaging/icon_test.go +++ b/utils/imaging/icon_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGenerateIcon(t *testing.T) { @@ -11,9 +12,12 @@ func TestGenerateIcon(t *testing.T) { assert := assert.New(t) - icon1 := GenerateIcon("a") - icon2 := GenerateIcon("b") - icon3 := GenerateIcon("b") + icon1, err := GenerateIcon("a") + require.NoError(t, err) + icon2, err := GenerateIcon("b") + require.NoError(t, err) + icon3, err := GenerateIcon("b") + require.NoError(t, err) if assert.NotNil(icon1) && assert.NotNil(icon2) && assert.NotNil(icon3) { assert.NotEqual(icon1, icon2)