From c3e9478235912edac02eac4bf9777846201ee943 Mon Sep 17 00:00:00 2001 From: Graham Barber Date: Fri, 16 Aug 2024 23:08:03 -0700 Subject: [PATCH] correctly determine and store microformat post type --- models/post.go | 6 ++++-- services/micropub.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/models/post.go b/models/post.go index be3ce0b..24d8316 100644 --- a/models/post.go +++ b/models/post.go @@ -3,6 +3,7 @@ package models import ( "time" + "go.hacdias.com/indielib/microformats" "gorm.io/datatypes" "gorm.io/gorm" ) @@ -10,8 +11,9 @@ import ( type Post struct { ID ULID `gorm:"primaryKey;unique"` - Type string - Properties datatypes.JSON + Type string + MicroformatType microformats.Type + Properties datatypes.JSON CreatedAt time.Time UpdatedAt time.Time diff --git a/services/micropub.go b/services/micropub.go index 630c4cb..c7d301a 100644 --- a/services/micropub.go +++ b/services/micropub.go @@ -21,6 +21,7 @@ import ( "github.com/h2non/filetype" "github.com/samber/lo" + "go.hacdias.com/indielib/microformats" "go.hacdias.com/indielib/micropub" ) @@ -102,10 +103,16 @@ func (m *Micropub) Create(req *micropub.Request) (string, error) { return "", err } + mfType, _ := microformats.DiscoverType(map[string]any{ + "type": req.Type, + "properties": req.Properties, + }) + post := &models.Post{ - ID: models.NewULID(), - Type: req.Type, - Properties: props, + ID: models.NewULID(), + Type: req.Type, + MicroformatType: mfType, + Properties: props, } res := storage.GORM().Create(post) -- 2.51.2