diff --git a/app/model/user_image.go b/app/model/user_image.go index b48894a..9576869 100644 --- a/app/model/user_image.go +++ b/app/model/user_image.go @@ -96,6 +96,14 @@ func (u *UserImage) GetByPath(path string) error { return nil } +func ExportUserImageId(url string) string { + img := ExportUserImage(url) + if img != nil { + return img.Id() + } + return "" +} + func ExportUserImage(url string) *UserImage { parts := strings.Split(url, "/") if len(parts) < 3 { diff --git a/user_image_test.go b/user_image_test.go index f480586..8d611f2 100644 --- a/user_image_test.go +++ b/user_image_test.go @@ -53,3 +53,12 @@ func TestExportUserImage(t *testing.T) { } fmt.Println(img.FileType) } + +func TestExportUserImageId(t *testing.T) { + imgUrl := "http://127.0.0.1:9011/img/avatar/6367d24adff5ddb91b5e07f9.png" + id := model.ExportUserImageId(imgUrl) + if id == "" { + t.Error("查询失败") + return + } +}