@@ 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 {
@@ 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)
}