From c0329c2cc8a49d9b0b088620b6f0b1bb96426dc5 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Thu, 23 May 2024 12:05:01 -0600 Subject: [PATCH] Fixing HTML import hash issue --- core/import.go | 3 ++- models/org_link.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/import.go b/core/import.go index 10c6da1..79bf55a 100644 --- a/core/import.go +++ b/core/import.go @@ -12,6 +12,7 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/labstack/echo/v4" + "github.com/segmentio/ksuid" "golang.org/x/net/html" "netlandish.com/x/gobwebs/database" "netlandish.com/x/gobwebs/server" @@ -146,7 +147,7 @@ func (h *htmlObj) SetHash(_ string) { } func (h htmlObj) GetHash() string { - return "" + return ksuid.New().String() } func (h htmlObj) IsUnread() bool { diff --git a/models/org_link.go b/models/org_link.go index 03705b2..ddb737c 100644 --- a/models/org_link.go +++ b/models/org_link.go @@ -10,6 +10,7 @@ import ( "time" sq "github.com/Masterminds/squirrel" + "github.com/segmentio/ksuid" "netlandish.com/x/gobwebs/database" "netlandish.com/x/gobwebs/timezone" ) @@ -130,6 +131,9 @@ func (o *OrgLink) Store(ctx context.Context) error { err := database.WithTx(ctx, nil, func(tx *sql.Tx) error { var err error if o.ID == 0 { + if o.Hash == "" { + o.Hash = ksuid.New().String() + } err = sq. Insert("org_links"). Columns("title", "url", "description", "base_url_id", "org_id", "user_id", "visibility", @@ -264,6 +268,9 @@ func OrgLinkStoreBatch(ctx context.Context, links []*OrgLink) error { "hash", "type", "unread") for _, link := range links { + if link.Hash == "" { + link.Hash = ksuid.New().String() + } batch = batch.Values(link.Title, link.URL, link.Description, link.BaseURLID, link.OrgID, link.UserID, link.Visibility, link.Hash, link.Type, link.Unread) } -- 2.45.2