mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update memo create activity (#903)
This commit is contained in:
@@ -87,6 +87,11 @@ type ActivityUserAuthSignUpPayload struct {
|
|||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ActivityMemoCreatePayload struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Visibility string `json:"visibility"`
|
||||||
|
}
|
||||||
|
|
||||||
type ActivityShortcutCreatePayload struct {
|
type ActivityShortcutCreatePayload struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Payload string `json:"payload"`
|
Payload string `json:"payload"`
|
||||||
|
@@ -9,9 +9,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/usememos/memos/api"
|
"github.com/usememos/memos/api"
|
||||||
"github.com/usememos/memos/common"
|
"github.com/usememos/memos/common"
|
||||||
metric "github.com/usememos/memos/plugin/metrics"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -60,9 +60,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create memo").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create memo").SetInternal(err)
|
||||||
}
|
}
|
||||||
s.Collector.Collect(ctx, &metric.Metric{
|
if err := s.createMemoCreateActivity(c, memo); err != nil {
|
||||||
Name: "memo created",
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
||||||
})
|
}
|
||||||
|
|
||||||
for _, resourceID := range memoCreate.ResourceIDList {
|
for _, resourceID := range memoCreate.ResourceIDList {
|
||||||
if _, err := s.Store.UpsertMemoResource(ctx, &api.MemoResourceUpsert{
|
if _, err := s.Store.UpsertMemoResource(ctx, &api.MemoResourceUpsert{
|
||||||
@@ -565,3 +565,22 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
return c.JSON(http.StatusOK, true)
|
return c.JSON(http.StatusOK, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) createMemoCreateActivity(c echo.Context, memo *api.Memo) error {
|
||||||
|
ctx := c.Request().Context()
|
||||||
|
payload := api.ActivityMemoCreatePayload{
|
||||||
|
Content: memo.Content,
|
||||||
|
Visibility: memo.Visibility.String(),
|
||||||
|
}
|
||||||
|
payloadStr, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to marshal activity payload")
|
||||||
|
}
|
||||||
|
_, err = s.Store.CreateActivity(ctx, &api.ActivityCreate{
|
||||||
|
CreatorID: memo.CreatorID,
|
||||||
|
Type: api.ActivityMemoCreate,
|
||||||
|
Level: api.ActivityInfo,
|
||||||
|
Payload: string(payloadStr),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@@ -38,6 +38,10 @@ func (raw *activityRaw) toActivity() *api.Activity {
|
|||||||
|
|
||||||
// CreateActivity creates an instance of Activity.
|
// CreateActivity creates an instance of Activity.
|
||||||
func (s *Store) CreateActivity(ctx context.Context, create *api.ActivityCreate) (*api.Activity, error) {
|
func (s *Store) CreateActivity(ctx context.Context, create *api.ActivityCreate) (*api.Activity, error) {
|
||||||
|
if s.profile.Mode != "dev" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
tx, err := s.db.BeginTx(ctx, nil)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, FormatError(err)
|
return nil, FormatError(err)
|
||||||
|
Reference in New Issue
Block a user